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


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

本文整理汇总了C++中atomic::load方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::load方法的具体用法?C++ atomic::load怎么用?C++ atomic::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在atomic的用法示例。


在下文中一共展示了atomic::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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

示例2: flushInBackground

	int flushInBackground()
	{
		vector<std::pair<unsigned int,unsigned int>>& vec = *consumerVec.load();
		if (vec.size() > 0){
			std::stable_sort(vec.begin(),vec.end(),postingComp());

			unsigned int wordid = vec[0].second;
			shared_ptr<Set> docSet = getOrCreate(wordid);
			unsigned int last = vec[0].first;
			for (auto posting : vec){
				if (posting.second != wordid){
					batchPut(wordid, docSet);
					docSet = getOrCreate(posting.second);
					wordid = posting.second;
					last = posting.first;
				}
				docSet->addDoc(posting.first);
				assert(posting.first >= last);
				last = posting.first;

			}
			batchPut(wordid, docSet);
			vec.clear();
		}

		store->Write(batch);
		batch.Clear();
		return 1;
	}
开发者ID:yovnchine,项目名称:zsearch,代码行数:29,代码来源:InvertedIndexBatch.hpp

示例3: push

	void push(T const& data) {
		node* const new_node = new node(data);
		new_node->next = head.load();
		//the cew check if the head equal to new_node->next, if it does, replace head with new_node
		//if it doesn't, replace the new_node->next with head.(because meanwhile the head has already been modified)
		while (!head.compare_exchange_weak(new_node->next, new_node));
	}
开发者ID:dingyiheng,项目名称:Concurrency,代码行数:7,代码来源:lock_free.cpp

示例4: FlightLoopCallback

float FlightLoopCallback(float inElapsedSinceLastCall,
                         float inElapsedTimeSinceLastFlightLoop, int inCounter,
                         void* inRefcon)
{
    if (!gPluginEnabled.load()) {
    }
    return 1.0;
}
开发者ID:jpoirier,项目名称:xplane-commviewer-plugin,代码行数:8,代码来源:commviewer.cpp

示例5: GETSINGLE

EXTERN_FORM DLL_API Dvoid __cdecl coold_LoadMeshFromFile( const Dchar* filename )
{		
	GETSINGLE(MeshManager).Clear();	
	GETSINGLE(MeshManager).LoadMesh(filename);

	//쓰레드 테스트를 위한 추가 로직----------------------------------	
	for (Dint i = 0; i < g_sGridCount.load() * g_sGridCount.load() - 1; ++i)
	{
		CustomMesh* pMesh = GETSINGLE(MeshManager).GetMesh(filename);
		if (CustomMeshPLY* pPlyMesh = dynamic_cast<CustomMeshPLY*>(pMesh))
		{
			CustomMesh* pNewMesh = new CustomMeshPLY(*pPlyMesh);
			GETSINGLE(MeshManager).AddMesh(filename + to_string(i), pNewMesh);
		}		
	}
	//-----------------------------------------------------------
}
开发者ID:realD86,项目名称:Rasterizer,代码行数:17,代码来源:coold.cpp

示例6: SerializeTask

Dvoid SerializeTask( Dbool threadUse )
{	
	if (g_sGridChangeCount.load() * g_sGridChangeCount.load() != (signed)GETSINGLE(MeshManager).GetMapMesh().size())
	{
		atomic_exchange(&g_sGridCount, g_sGridChangeCount.load());
		string strFileName( (*GETSINGLE(MeshManager).GetMapMesh().begin()).first );
		coold_LoadMeshFromFile(strFileName.c_str());
	}
	
	if (threadUse != g_sThreadUse.load())
	{
		g_pThreadManager->CleanThreads();

		if (g_sThreadUse.load())
		{	//쓰레드 사용시에만 초기화
			g_pThreadManager->Initialize(0);
		}
	}

	if (g_sThreadCount.load() != 0)
	{
		g_pThreadManager->ResetThreads(g_sThreadCount.load());
		atomic_exchange(&g_sThreadCount, 0);
	}
}
开发者ID:realD86,项目名称:Rasterizer,代码行数:25,代码来源:coold.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: allocateThread

void allocateThread(const atomic<bool>& done)
{
  while (!done.load())
  {
    void* mem = malloc(500);
    free(mem);
    ros::WallDuration(0.001).sleep();
  }
}
开发者ID:HiroyukiMikita,项目名称:usc-clmc-ros-pkg,代码行数:9,代码来源:test_malloc_wrappers.cpp

示例9: add

	int add(unsigned int wordId, unsigned int docid)
	{
		m.Lock();
		producerVec.load()->push_back(std::pair<unsigned int,unsigned int>(docid,wordId));
		batchsize +=1;
		cond_var.Signal();
		m.Unlock();
		return 1;
	}
开发者ID:yovnchine,项目名称:zsearch,代码行数:9,代码来源:InvertedIndexBatch.hpp

示例10: while

 static void
 thread_fn(unique_ptr<worker> &w,
           const atomic<bool> &start_flag,
           const atomic<bool> &stop_flag)
 {
   while (!start_flag.load())
     nop_pause();
   w->run(stop_flag);
 }
开发者ID:mindis,项目名称:scalex,代码行数:9,代码来源:bench.cpp

示例11: consumer_main

	void consumer_main(){
	    while (!done) {
		    m.Lock();
		    if (batchsize > 0){
				vector<std::pair<unsigned int,unsigned int>>* temp;
				temp = producerVec.load();
				producerVec.store(consumerVec.load());
				consumerVec.store(temp);
				batchsize = 0;
				cond_var.Signal();
		    } else {
			   // sleep
			   while (batchsize == 0 && !done){
			     cond_var.Wait();
			   }
		    }
	        m.Unlock();
			flushInBackground();
	    }
	}
开发者ID:yovnchine,项目名称:zsearch,代码行数:20,代码来源:InvertedIndexBatch.hpp

示例12: main

int main() {
    promise<int> prom;
    future<int> fut = prom.get_future();
    thread one(worker1,move(fut));
    thread two(worker2,move(prom));
    while(flag.load() == 0);
    one.detach();
    two.detach();

    pthread_exit(NULL);
    printf("main thread exit!\n");
    return 0;
}
开发者ID:evely211,项目名称:Norman,代码行数:13,代码来源:NThreadPromise.cpp

示例13: pull

	unsigned int pull()
	{
		int stage = _stage.load( std::memory_order_relaxed );
		bool changed = _state[stage].changed.load( std::memory_order_relaxed );

		if( changed )
		{
			_state[_out].changed.store( false, std::memory_order_relaxed );
			_out = _stage.exchange( _out, std::memory_order_acquire );
		  return _state[_out].frames;
		}
    return 0;
	}
开发者ID:Angeldude,项目名称:sonic-pi,代码行数:13,代码来源:scope_buffer.hpp

示例14: param

EXTERN_FORM DLL_API Dvoid __cdecl coold_RenderToBuffer(Dvoid* buffer, Dint width, Dint height, Dint bpp)
{
	RenderModuleInit(buffer, width, height);

	int sequence = 0;
	bool threadUse = g_sThreadUse.load();
	for (auto& Mesh : GETSINGLE(MeshManager).GetMapMesh())
	{
		if ( threadUse )
		{
			if (g_sGridCount.load() > 1)
			{
				g_renderModule->AdjustGridWorld(g_sGridCount.load(), sequence++);
			}

			RenderInfoParam param(g_renderModule, Mesh.second);
			g_pThreadManager->AssignWork(&param);
		}
		else
		{
			if (g_sGridCount.load() > 1)
			{
				g_renderModule->AdjustGridWorld(g_sGridCount.load(), sequence++);
			}
			g_renderModule->RenderBegin(Mesh.second);
			g_renderModule->RenderEnd();
		}
	}

	if ( threadUse )
		g_pThreadManager->WaitAllThreadWorking();
	
	//───────────────────────────────────────────────────────────────────────────────────
	//이 부분은 시리얼 동작한다.
	SerializeTask(threadUse);	
	//───────────────────────────────────────────────────────────────────────────────────

}
开发者ID:realD86,项目名称:Rasterizer,代码行数:38,代码来源:coold.cpp

示例15: foo

int foo(atomic<int>& x)
{
  for(size_t n = 0; ; ++n)
  {
    auto expected = x.load();
    auto desired = 0;
    x.compare_exchange_strong(
      expected,
      desired);

    if(n == loop)
      return desired;
  }
}
开发者ID:DemonGiggle,项目名称:ClangThreadSanitizerTests,代码行数:14,代码来源:threadsanitizer_atomic_int.cpp


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