本文整理汇总了C++中tbb::atomic::compare_and_swap方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::compare_and_swap方法的具体用法?C++ atomic::compare_and_swap怎么用?C++ atomic::compare_and_swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tbb::atomic
的用法示例。
在下文中一共展示了atomic::compare_and_swap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: incLoop
/*
* Use atomic compare-and-swap to update val to
* val + inc. Update occurs in a loop in case other
* threads update in the meantime.
*/
inline void incLoop(tbb::atomic<double>& val, double inc) {
double oldMass = val.load();
double returnedMass = oldMass;
double newMass{oldMass + inc};
do {
oldMass = returnedMass;
newMass = oldMass + inc;
returnedMass = val.compare_and_swap(newMass, oldMass);
} while (returnedMass != oldMass);
}
示例2: incLoopLog
/*
* Use atomic compare-and-swap to update val to
* val + inc (*in log-space*). Update occurs in a loop in case other
* threads update in the meantime.
*/
inline void incLoopLog(tbb::atomic<double>& val, double inc) {
double oldMass = val.load();
double returnedMass = oldMass;
double newMass{salmon::math::LOG_0};
do {
oldMass = returnedMass;
newMass = salmon::math::logAdd(oldMass, inc);
returnedMass = val.compare_and_swap(newMass, oldMass);
} while (returnedMass != oldMass);
}
示例3: logAddMass
inline void logAddMass(tbb::atomic<double>& bin,
double newMass) {
double oldVal = bin;
double retVal = oldVal;
double newVal = 0.0;
do {
oldVal = retVal;
newVal = salmon::math::logAdd(oldVal, newMass);
retVal = bin.compare_and_swap(newVal, oldVal);
} while (retVal != oldVal);
}
示例4: new
simplest_scheduler::simplest_scheduler( context_base &context, int numThreads, int htstride )
: scheduler_i( context ),
m_status(),
m_rootTask(),
m_initTBB( std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) ) ),
m_taskGroupContext( tbb::task_group_context::isolated, tbb::task_group_context::default_traits | tbb::task_group_context::concurrent_wait )
{
// {Speaker oss; oss << std::max( 2, numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) );}
if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
s_po = new pinning_observer( htstride );
}
m_status = COMPLETED;
m_rootTask = new( tbb::task::allocate_root( m_taskGroupContext ) ) tbb::empty_task;
m_rootTask->set_ref_count( 1 );
}
示例5:
simplest_prioritized_scheduler::simplest_prioritized_scheduler( context_base &context, int numThreads, int htstride )
: scheduler_i( context ),
m_runQueue(),
m_status(),
m_allocated(),
m_initTBB( numThreads + ( distributor::myPid() == 0 ? 0 : 1 ) ),
m_applyStepInstance( NULL )
{
if( htstride && s_have_pinning_observer.compare_and_swap( true, false ) == false ) {
s_po = new pinning_observer( htstride );
}
m_status = COMPLETED;
m_allocated = false;
if( m_allocated.compare_and_swap( true, false ) == false ) {
m_applyStepInstance = new apply_step_instance();
}
}