本文整理汇总了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;
}
}
示例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;
}
示例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));
}
示例4: FlightLoopCallback
float FlightLoopCallback(float inElapsedSinceLastCall,
float inElapsedTimeSinceLastFlightLoop, int inCounter,
void* inRefcon)
{
if (!gPluginEnabled.load()) {
}
return 1.0;
}
示例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);
}
}
//-----------------------------------------------------------
}
示例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);
}
}
示例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: allocateThread
void allocateThread(const atomic<bool>& done)
{
while (!done.load())
{
void* mem = malloc(500);
free(mem);
ros::WallDuration(0.001).sleep();
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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(¶m);
}
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);
//───────────────────────────────────────────────────────────────────────────────────
}
示例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;
}
}