本文整理汇总了C++中atomic::store方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::store方法的具体用法?C++ atomic::store怎么用?C++ atomic::store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomic
的用法示例。
在下文中一共展示了atomic::store方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: statsThread
void statsThread(atomic<bool>& failed)
{
resetThreadAllocInfo();
for (uint32_t i = 1; i <= 1000; ++i)
{
void* mem = malloc(500);
free(mem);
ros::WallDuration(0.001).sleep();
AllocInfo info = getThreadAllocInfo();
if (info.mallocs != i)
{
ROS_ERROR_STREAM("mallocs is " << info.mallocs << " should be " << i);
failed.store(true);
return;
}
if (info.frees != i)
{
ROS_ERROR_STREAM("mallocs is " << info.frees << " should be " << i);
failed.store(true);
return;
}
}
}
示例2: CommandHandler
int CommandHandler(XPLMCommandRef inCommand, XPLMCommandPhase inPhase,
void* inRefcon)
{
// if (!gPluginEnabled.load()) {
// return IGNORED_EVENT;
// }
switch (reinterpret_cast<size_t>(inRefcon)) {
case CMD_CONTACT_ATC:
switch (inPhase) {
case xplm_CommandBegin:
case xplm_CommandContinue:
gPTT_On.store(true);
break;
case xplm_CommandEnd:
gPTT_On.store(false);
break;
default:
break;
}
break;
default:
break;
}
return IGNORED_EVENT;
}
示例3: run_test
void run_test(void)
{
freelist_type fl(std::allocator<int>(), 8);
std::set<dummy*> nodes;
dummy d;
if (bounded)
test_running.store(true);
for (int i = 0; i != 4; ++i) {
dummy * allocated = fl.template construct<threadsafe, bounded>();
BOOST_REQUIRE(nodes.find(allocated) == nodes.end());
nodes.insert(allocated);
}
BOOST_FOREACH(dummy * d, nodes)
fl.template destruct<threadsafe>(d);
nodes.clear();
for (int i = 0; i != 4; ++i)
nodes.insert(fl.template construct<threadsafe, bounded>());
BOOST_FOREACH(dummy * d, nodes)
fl.template destruct<threadsafe>(d);
for (int i = 0; i != 4; ++i)
nodes.insert(fl.template construct<threadsafe, bounded>());
if (bounded)
test_running.store(false);
}
示例4: run
void run(queue & stk)
{
BOOST_WARN(stk.is_lock_free());
running.store(true);
thread_group writer;
thread_group reader;
BOOST_REQUIRE(stk.empty());
for (int i = 0; i != reader_threads; ++i)
reader.create_thread(boost::bind(&queue_stress_tester::template get_items<queue>, this, boost::ref(stk)));
for (int i = 0; i != writer_threads; ++i)
writer.create_thread(boost::bind(&queue_stress_tester::template add_items<queue>, this, boost::ref(stk)));
using namespace std;
cout << "threads created" << endl;
writer.join_all();
cout << "writer threads joined, waiting for readers" << endl;
running = false;
reader.join_all();
cout << "reader threads joined" << endl;
BOOST_REQUIRE_EQUAL(data.count_nodes(), 0);
BOOST_REQUIRE(stk.empty());
BOOST_REQUIRE_EQUAL(push_count, pop_count);
BOOST_REQUIRE_EQUAL(push_count, writer_threads * node_count);
}
示例5: onJoinSuccess
void PstnThread::onJoinSuccess(const char *cname, unsigned uid, const char *msg) {
(void)cname;
(void)uid;
joined_flag_.store(true);
LOG(INFO, "Joined the channel %s: %s", cname, msg);
}
示例6: populate_queue
void populate_queue() {
unsigned const number_of_items=20;
queue_data.clear();
for(unsigned i=0; i<number_of_items; ++i) {
queue_data.push_back(i);
}
count.store(number_of_items,memory_order_release);
}
示例7: release
void release( scope_buffer_pool & pool )
{
bool allocated = _status.load( boost::memory_order_relaxed ) != free;
if( !allocated ) return;
pool.deallocate( _data.get() );
_status.store( free, boost::memory_order_release );
}
示例8: consumer_main
InvertedIndexBatch(std::shared_ptr<KVStore::IKVStore> store, shared_ptr<ISetFactory> setFactory) :
store(store),
setFactory(setFactory),
cond_var(&m)
{
void consumer_main();
maxbatchsize = 2500000;
batchsize = 0;
store->Open();
producerVec.store(&postings);
consumerVec.store(&postings2);
consumerThread = std::thread([this](){
this->consumer_main();
});
}
示例9: run
void run()
{
running = true;
if (bounded)
test_running.store(true);
boost::thread_group alloc_threads;
boost::thread_group dealloc_threads;
for (int i = 0; i != thread_count; ++i)
dealloc_threads.create_thread(boost::bind(&freelist_tester::deallocate, this));
for (int i = 0; i != thread_count; ++i)
alloc_threads.create_thread(boost::bind(&freelist_tester::allocate, this));
alloc_threads.join_all();
test_running.store(false);
running = false;
dealloc_threads.join_all();
}
示例10: await
bool await(function<void()> cb = []{}) {
int my_gen = generation.load();
if (count.fetch_add(1) == N_THREADS - 1) {
if (cb) cb();
count.store(0);
generation.fetch_add(1);
return true;
} else {
do { } while (my_gen == generation.load());
return false;
}
}
示例11: srand
void *sampleTimer(void*v){
srand( time(NULL) );
samplingOn = false;
while(true){
/*Non-Sampling Period*/
usleep(NON_SAMPLE_PERIOD);
/*Sample Generation is ordered by samplingOn's fence*/
unsigned long t = sampleGeneration.load(memory_order_acquire);
sampleGeneration.store(t + 1, memory_order_release);
samplingOn.store(true, memory_order_release);
/*Non-Sampling Period*/
while( samplingOn.load(memory_order_acquire) ){
usleep(SAMPLE_QUANTUM);
}
}
}
示例12: IncrementSharedValue10000000Times
void IncrementSharedValue10000000Times(RandomDelay& randomDelay)
{
int count = 0;
while (count < 10000000)
{
randomDelay.doBusyWork();
int expected = 0;
if (flag.compare_exchange_strong(expected, 1, memory_order_relaxed))
{
// Lock was successful
sharedValue++;
flag.store(0, memory_order_relaxed);
count++;
}
}
}
示例13: allocate
bool allocate( scope_buffer_pool & pool, unsigned int channels, unsigned int size )
{
bool available = _status.load( boost::memory_order_relaxed ) == free;
if( !available ) return false;
_size = size;
_channels = channels;
unsigned int asset_size = channels * size;
_data = (float*)pool.allocate( asset_size * 3 * sizeof(float) );
if (_data == NULL)
return false;
_state[0].data = _data;
_state[1].data = _data + asset_size;
_state[2].data = _data + asset_size + asset_size;
_status.store( initialized, boost::memory_order_release );
return true;
}
示例14: ValueSet
int ValueSet(int) {
int t = 1;
a.store(t, memory_order_relaxed);
b.store(2, memory_order_relaxed);
}
示例15: initOwner
void initOwner() {
owner.store(-1);
}