本文整理汇总了C++中Dispatcher::interrupted方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::interrupted方法的具体用法?C++ Dispatcher::interrupted怎么用?C++ Dispatcher::interrupted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::interrupted方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: InterruptedException
TEST(ContextTests, interruptIsInterrupting) {
Dispatcher dispatcher;
Context<> context(dispatcher, [&] {
if (dispatcher.interrupted()) {
throw InterruptedException();
}
});
context.interrupt();
ASSERT_THROW(context.get(), InterruptedException);
}
示例3: context
TEST(ContextTests, destructorInterrupts) {
Dispatcher dispatcher;
bool interrupted = false;
{
Context<> context(dispatcher, [&] {
if (dispatcher.interrupted()) {
interrupted = true;
}
});
}
ASSERT_TRUE(interrupted);
}
示例4:
TEST(ContextGroupTests, ContextGroupInterruptIsInterrupting) {
Dispatcher dispatcher;
bool interrupted = false;
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
interrupted = dispatcher.interrupted();
});
cg1.interrupt();
cg1.wait();
ASSERT_TRUE(interrupted);
}
示例5: Timer
TEST(ContextGroupTests, ContextGroupDestructorIsInterrupt_Waitable) {
Dispatcher dispatcher;
bool interrupted = false;
bool contextFinished = false;
{
ContextGroup cg1(dispatcher);
cg1.spawn([&] {
interrupted = dispatcher.interrupted();
Timer(dispatcher).sleep(std::chrono::milliseconds(100));
contextFinished = true;
});
}
ASSERT_TRUE(interrupted);
ASSERT_TRUE(contextFinished);
}
示例6: event
TEST(ContextTests, getChecksInterruption) {
Dispatcher dispatcher;
Event event(dispatcher);
Context<int> context1(dispatcher, [&] {
event.wait();
if (dispatcher.interrupted()) {
return 11;
}
return 10;
});
Context<int> context2(dispatcher, [&] {
event.set();
return context1.get();
});
context2.interrupt();
ASSERT_EQ(11, context2.get());
}