本文整理汇总了C++中AutoRequired::Stop方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoRequired::Stop方法的具体用法?C++ AutoRequired::Stop怎么用?C++ AutoRequired::Stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoRequired
的用法示例。
在下文中一共展示了AutoRequired::Stop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pshr
TEST_F(ObjectPoolTest, VerifyAsynchronousUsage) {
AutoCreateContext ctxt;
CurrentContextPusher pshr(ctxt);
AutoRequired<SimpleThreadedT<PooledObject>> obj;
AutoFired<SharedPtrReceiver<PooledObject>> spr;
ObjectPool<PooledObject> pool(3);
{
// Obtain the pool limit in objects:
std::shared_ptr<PooledObject> obj1, obj2, obj3;
pool(obj1);
pool(obj2);
pool(obj3);
ASSERT_TRUE(nullptr != obj1.get()) << "Failed to obtain an entry from a new object pool";
// Block--verify that we _do not_ get any of those objects back while they are
// still outstanding.
{
auto obj4 = pool.WaitFor(std::chrono::milliseconds(1));
EXPECT_TRUE(obj4 == nullptr) << "Pool issued another element even though it should have hit its outstanding limit";
}
// Now we kick off threads:
AutoCurrentContext()->Initiate();
// Fire off a few events:
spr(&SharedPtrReceiver<PooledObject>::OnEvent)(obj1);
spr(&SharedPtrReceiver<PooledObject>::OnEvent)(obj2);
spr(&SharedPtrReceiver<PooledObject>::OnEvent)(obj3);
}
// This should return more or less right away as objects become available:
{
auto obj4 = pool.WaitFor(std::chrono::milliseconds(10));
EXPECT_TRUE(obj4 != nullptr) << "Object pool failed to be notified that it received a new element";
}
// Cause the thread to quit:
*obj += [&obj] { obj->Stop(); };
obj->Wait();
}