本文整理汇总了C++中Executor::defer方法的典型用法代码示例。如果您正苦于以下问题:C++ Executor::defer方法的具体用法?C++ Executor::defer怎么用?C++ Executor::defer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Executor
的用法示例。
在下文中一共展示了Executor::defer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
TEST(ProcessTest, Executor)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
std::atomic_bool event1Called(false);
std::atomic_bool event2Called(false);
EventReceiver receiver;
EXPECT_CALL(receiver, event1(42))
.WillOnce(Assign(&event1Called, true));
EXPECT_CALL(receiver, event2("event2"))
.WillOnce(Assign(&event2Called, true));
Executor executor;
Deferred<void(int)> event1 =
executor.defer([&receiver](int i) {
return receiver.event1(i);
});
event1(42);
Deferred<void(const string&)> event2 =
executor.defer([&receiver](const string& s) {
return receiver.event2(s);
});
event2("event2");
while (event1Called.load() == false);
while (event2Called.load() == false);
}
示例2: while
TEST(Process, executor)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
volatile bool event1Called = false;
volatile bool event2Called = false;
EventReceiver receiver;
EXPECT_CALL(receiver, event1(42))
.WillOnce(Assign(&event1Called, true));
EXPECT_CALL(receiver, event2("event2"))
.WillOnce(Assign(&event2Called, true));
Executor executor;
deferred<void(int)> event1 =
executor.defer(std::tr1::bind(&EventReceiver::event1,
&receiver,
std::tr1::placeholders::_1));
event1(42);
deferred<void(const std::string&)> event2 =
executor.defer(std::tr1::bind(&EventReceiver::event2,
&receiver,
std::tr1::placeholders::_1));
event2("event2");
while (!event1Called);
while (!event2Called);
}