当前位置: 首页>>代码示例>>C++>>正文


C++ atomic::store方法代码示例

本文整理汇总了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;
    }
  }
}
开发者ID:HiroyukiMikita,项目名称:usc-clmc-ros-pkg,代码行数:26,代码来源:test_malloc_wrappers.cpp

示例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;
}
开发者ID:jpoirier,项目名称:xplane-commviewer-plugin,代码行数:26,代码来源:commviewer.cpp

示例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);
}
开发者ID:mokerjoke,项目名称:boost-svn,代码行数:32,代码来源:freelist_test.cpp

示例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);
    }
开发者ID:jmargeta,项目名称:boost-svn,代码行数:35,代码来源:test_common.hpp

示例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);
}
开发者ID:qipa-debate,项目名称:qipa-debate-server,代码行数:7,代码来源:main.cpp

示例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);
}
开发者ID:hp2oo1,项目名称:concurrency,代码行数:8,代码来源:solution.cpp

示例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 );
	}
开发者ID:dpalkowski,项目名称:iSuperColliderKit,代码行数:9,代码来源:scope_buffer.hpp

示例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();
		        });

	}
开发者ID:yovnchine,项目名称:zsearch,代码行数:18,代码来源:InvertedIndexBatch.hpp

示例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();
    }
开发者ID:mokerjoke,项目名称:boost-svn,代码行数:19,代码来源:freelist_test.cpp

示例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;
		}
	}
开发者ID:Feder1co5oave,项目名称:GameOfLife,代码行数:12,代码来源:Barrier_atomic.hpp

示例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); 

    }

  }

}
开发者ID:blucia0a,项目名称:CTraps-gcc,代码行数:24,代码来源:RWCalls.cpp

示例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++;
        }
    }
}
开发者ID:preshing,项目名称:AcquireRelease,代码行数:16,代码来源:main.cpp

示例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;
	}
开发者ID:dpalkowski,项目名称:iSuperColliderKit,代码行数:21,代码来源:scope_buffer.hpp

示例14: ValueSet

int ValueSet(int) {
    int t = 1;
    a.store(t, memory_order_relaxed);
    b.store(2, memory_order_relaxed);
}
开发者ID:morning-color,项目名称:data-structure,代码行数:5,代码来源:6-3-6.cpp

示例15: initOwner

 void initOwner() {
     owner.store(-1);
 }
开发者ID:alexlokotochek,项目名称:parallels_cpp,代码行数:3,代码来源:main.cpp


注:本文中的atomic::store方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。