本文整理汇总了C++中Atomic::load方法的典型用法代码示例。如果您正苦于以下问题:C++ Atomic::load方法的具体用法?C++ Atomic::load怎么用?C++ Atomic::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Atomic
的用法示例。
在下文中一共展示了Atomic::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: barrier
//==============================================================================
ANKI_TEST(Resource, AsyncLoader)
{
HeapAllocator<U8> alloc(allocAligned, nullptr);
// Simple create destroy
{
AsyncLoader a;
a.init(alloc);
}
// Simple task that will finish
{
AsyncLoader a;
a.init(alloc);
Barrier barrier(2);
a.submitNewTask<Task>(0.0, &barrier, nullptr);
barrier.wait();
}
// Many tasks that will finish
{
AsyncLoader a;
a.init(alloc);
Barrier barrier(2);
Atomic<U32> counter = {0};
const U COUNT = 100;
for(U i = 0; i < COUNT; i++)
{
Barrier* pbarrier = nullptr;
if(i == COUNT - 1)
{
pbarrier = &barrier;
}
a.submitNewTask<Task>(0.01, pbarrier, &counter);
}
barrier.wait();
ANKI_TEST_EXPECT_EQ(counter.load(), COUNT);
}
// Many tasks that will _not_ finish
{
AsyncLoader a;
a.init(alloc);
for(U i = 0; i < 100; i++)
{
a.submitNewTask<Task>(0.0, nullptr, nullptr);
}
}
// Tasks that allocate
{
AsyncLoader a;
a.init(alloc);
Barrier barrier(2);
for(U i = 0; i < 10; i++)
{
Barrier* pbarrier = nullptr;
if(i == 9)
{
pbarrier = &barrier;
}
a.submitNewTask<MemTask>(alloc, pbarrier);
}
barrier.wait();
}
// Tasks that allocate and never finished
{
AsyncLoader a;
a.init(alloc);
for(U i = 0; i < 10; i++)
{
a.submitNewTask<MemTask>(alloc, nullptr);
}
}
// Pause/resume
{
AsyncLoader a;
a.init(alloc);
Atomic<U32> counter(0);
Barrier barrier(2);
// Check if the pause will sync
a.submitNewTask<Task>(0.5, nullptr, &counter, 0);
HighRezTimer::sleep(0.25); // Wait for the thread to pick the task...
a.pause(); /// ...and then sync
//.........这里部分代码省略.........