本文整理汇总了C++中Dispatcher::yield方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::yield方法的具体用法?C++ Dispatcher::yield怎么用?C++ Dispatcher::yield使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::yield方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: event
TEST(EventTests, waitIsWaiting) {
Dispatcher dispatcher;
Event event(dispatcher);
bool done = false;
Context<> context(dispatcher, [&]() {
event.wait();
done = true;
});
dispatcher.yield();
ASSERT_FALSE(done);
event.set();
dispatcher.yield();
ASSERT_TRUE(done);
}
示例2: Timer
TEST(ContextGroupTests, ContextGroupIsWaitingNestedSpawnsEvenThoughItWasInterrupted) {
Dispatcher dispatcher;
bool contextFinished = false;
bool nestedContextFinished = false;
{
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
try {
Timer(dispatcher).sleep(std::chrono::milliseconds(100));
contextFinished = true;
} catch (InterruptedException&) {
cg1.spawn([&] {
try {
Timer(dispatcher).sleep(std::chrono::milliseconds(100));
nestedContextFinished = true;
} catch (InterruptedException&) {
}
});
}
});
dispatcher.yield();
}
ASSERT_FALSE(contextFinished);
ASSERT_TRUE(nestedContextFinished);
}
示例3: event
TEST(EventLockTests, eventLockIsLocking) {
Dispatcher dispatcher;
Event event(dispatcher);
bool done = false;
Context<> context(dispatcher, [&]() {
EventLock lock(event);
done = true;
});
ASSERT_FALSE(done);
dispatcher.yield();
ASSERT_FALSE(done);
event.set();
dispatcher.yield();
ASSERT_TRUE(done);
}
示例4: connected
TEST(ContextGroupTests, ConnectionWriteIsThrowingWhenCurrentContextIsInterrupted) {
Dispatcher dispatcher;
bool interrupted = false;
{
Event connected(dispatcher);
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
try {
auto conn = TcpListener(dispatcher, Ipv4Address("0.0.0.0"), 12345).accept();
conn.write(nullptr, 0);
} catch (InterruptedException&) {
}
});
cg1.spawn([&] {
try {
auto conn = TcpConnector(dispatcher).connect(Ipv4Address("127.0.0.1"), 12345);
connected.set();
dispatcher.yield();
conn.write(nullptr, 0);
} catch (InterruptedException&) {
interrupted = true;
}
});
connected.wait();
}
ASSERT_TRUE(interrupted);
}
示例5:
TEST(ContextGroupTests, ContextGroupWaitIsWaiting) {
Dispatcher dispatcher;
bool contextFinished = false;
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
dispatcher.yield();
contextFinished = true;
});
cg1.wait();
ASSERT_TRUE(contextFinished);
}
示例6: context
TEST(ContextGroupTests, DispatcherInterruptSetsFlag) {
Dispatcher dispatcher;
Context<> context(dispatcher, [&] {
try {
Timer(dispatcher).sleep(std::chrono::milliseconds(10));
} catch (InterruptedException&) {
}
});
dispatcher.interrupt();
dispatcher.yield();
ASSERT_TRUE(dispatcher.interrupted());
ASSERT_FALSE(dispatcher.interrupted());
}
示例7: e
TEST(ContextGroupTests, testHangingUp) {
Dispatcher dispatcher;
Event e(dispatcher);
Context<> context(dispatcher, [&] {
Timer(dispatcher).sleep(std::chrono::milliseconds(100));
});
Context<> contextSecond(dispatcher, [&] {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
e.set();
dispatcher.yield();
});
e.wait();
}
示例8: TcpConnector
TEST(ContextGroupTests, ConnectorConnectIsContextIntrerruptible) {
Dispatcher dispatcher;
bool interrupted = false;
{
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
try {
TcpConnector(dispatcher).connect(Ipv4Address("127.0.0.1"), 12345);
} catch (InterruptedException&) {
interrupted = true;
}
});
dispatcher.yield();
}
ASSERT_TRUE(interrupted);
}
示例9: TcpListener
TEST(ContextGroupTests, ListenerAcceptIsContextIntrerruptible) {
Dispatcher dispatcher;
bool interrupted = false;
{
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
try {
TcpListener(dispatcher, Ipv4Address("0.0.0.0"), 12345).accept();
} catch (InterruptedException&) {
interrupted = true;
}
});
dispatcher.yield();
}
ASSERT_TRUE(interrupted);
}