本文整理汇总了C++中EventBase::waitUntilRunning方法的典型用法代码示例。如果您正苦于以下问题:C++ EventBase::waitUntilRunning方法的具体用法?C++ EventBase::waitUntilRunning怎么用?C++ EventBase::waitUntilRunning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventBase
的用法示例。
在下文中一共展示了EventBase::waitUntilRunning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: atoms
// This test simulates some calls, and verifies that the waiting happens by
// triggering what otherwise would be race conditions, and trying to detect
// whether any of the race conditions happened.
TEST(EventBaseTest, RunInEventBaseThreadAndWait) {
const size_t c = 256;
vector<unique_ptr<atomic<size_t>>> atoms(c);
for (size_t i = 0; i < c; ++i) {
auto& atom = atoms.at(i);
atom = make_unique<atomic<size_t>>(0);
}
vector<thread> threads(c);
for (size_t i = 0; i < c; ++i) {
auto& atom = *atoms.at(i);
auto& th = threads.at(i);
th = thread([&atom] {
EventBase eb;
auto ebth = thread([&]{ eb.loopForever(); });
eb.waitUntilRunning();
eb.runInEventBaseThreadAndWait([&] {
size_t x = 0;
atom.compare_exchange_weak(
x, 1, std::memory_order_release, std::memory_order_relaxed);
});
size_t x = 0;
atom.compare_exchange_weak(
x, 2, std::memory_order_release, std::memory_order_relaxed);
eb.terminateLoopSoon();
ebth.join();
});
}
for (size_t i = 0; i < c; ++i) {
auto& th = threads.at(i);
th.join();
}
size_t sum = 0;
for (auto& atom : atoms) sum += *atom;
EXPECT_EQ(c, sum);
}