草庐IT

q_atomic_increment

全部标签

C++ : List iterator not incrementable

尝试删除列表的最后一个元素时出现此错误。我调试了代码并且能够找出导致它的原因和位置,这是我的代码:for(Drop_List_t::iteratori=Drop_System.begin();i!=Drop_System.end()&&!Drop_System_Disable;/**/){if(Player->BoundingBox.Intersect(&(*i)->BoundingBox)){i=Drop_System.erase(i);}++i;//Listiteratorcrasheshereiflastentrywasdeleted}我不知道我做错了什么……有什么建议吗?

c++ - std::atomic 将一对原子 int32 视为一个原子 int64?

我有一对unsignedint32std::atomic_start;std::atomic_end;有时我想通过比较交换来设置开始或结束,所以我不希望在整个64位对上使用CAS可能导致虚假故障。我只想使用32位CAS。_end.compare_exchange_strong(old_end,new_end);现在我可以将开始和结束作为一个64位原子读取来获取。或者两个单独的32位读取。执行一次64位原子提取(编译器添加适当的内存栅栏)而不是使用两个内存栅栏进行两次单独的32原子位读取(或者编译器会优化它吗?)会不会更快?如果是这样,我将如何在C++11中做到这一点?

c++ - std::atomic::load 的内存排序行为

我是否错误地假设atomic::load也应该充当内存屏障以确保所有先前的非原子写入将对其他线程可见?举例说明:volatileboolarm1=false;std::atomic_boolarm2=false;booltriggered=false;线程1:arm1=true;//std::std::atomic_thread_fence(std::memory_order_seq_cst);//thiswoulddothetrickif(arm2.load())triggered=true;线程2:arm2.store(true);if(arm1)triggered=true;我预

c++ - 使用 atomic_flag 自旋锁进行内存排序

我正在尝试熟悉c++11的新内存排序概念,并且相信我实际上已经很好地掌握了它们,直到我偶然发现了自旋锁的这个实现:#includenamespaceJayZ{namespaceTools{classSpinLock{private:std::atomic_flagspin_lock;public:inlineSpinLock(void):atomic_flag(ATOMIC_FLAG_INIT){}inlinevoidlock(void){while(spin_lock.test_and_set(std::memory_order_acquire));}inlinevoidunlock

c++ - std::atomic<double> & 的模板特化

我有这个MCVE:#include#includetemplatevoidassertVariableHasBeenSet(T,constchar*);templatevoidassertVariableHasBeenSet&>(std::atomic&myDouble,constchar*variableName){printf("Double:%s=%f\n",variableName,myDouble.load());};intmain(){std::atomicmyDoubleAtomic{23.45};assertVariableHasBeenSet(myDoubleAtom

c++ - is_lock_free 未在 gcc 4.7.2 的 std::atomic<T> 中定义?

我遇到这个编译器错误functionstd::atomic::is_lock_free()const:error:undefinedreferenceto'__atomic_is_lock_free'whencompilingcodelikebelowusinggcc4.7.2onlinux.structS{inta;intb;};std::atomics;cout 最佳答案 AtomicAPIisn'tcompleteinGCC4.7:Whenlockfreeinstructionsarenotavailable(eitherth

c++ - c++11(atomic)的获取释放操作

#include#include#includeclassatomicAcquireRelease00{public:atomicAcquireRelease00():x(false),y(false),z(0){}voidrun(){std::threada(&atomicAcquireRelease00::write_x,this);std::threadb(&atomicAcquireRelease00::write_y,this);std::threadc(&atomicAcquireRelease00::read_x_then_y,this);std::threadd(&at

c++ - 我需要 std::atomic<bool> 还是 POD bool 足够好?

考虑这段代码://globalstd::atomicrun=true;//thread1while(run){/*dostuff*/}//thread2/*dostuffuntilit'stimetoshutdown*/run=false;我在这里需要与原子变量相关的开销吗?我的直觉是,bool变量的读/写或多或少是原子的(这是一个常见的g++/Linux/Intel设置),如果有一些写/读时序异常,我在线程1上的运行循环会停止一个结果是早晚通过,对于这个应用程序我不是很担心。还是我在这里遗漏了一些其他考虑因素?查看perf,我的代码似乎在std::atomic_bool::opera

c++ - 警告 LNK4075 : ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification

我有一个链接到外部.lib(libprotobuf.lib)的项目。当我在发行版中编译时,没有警告。但是,当我在调试中编译时,我收到此警告:warningLNK4075:ignoring'/EDITANDCONTINUE'dueto'/INCREMENTAL:NO'specificationFile:\libprotobuf.lib(message_lite.obj)我一直在研究这个问题,从thisquestion.开始我一直在调整项目的选项,并且(在调试配置中):/Zi-所以编辑并继续不应该打开。/INCREMENTAL-所以增量应该打开。知道为什么我仍然收到此警告吗?我最好的猜测是

c++ - GCCs atomic builtins - 支持哪些处理器

Thisdocument说:Notalloperationsaresupportedbyalltargetprocessors.有人知道哪个处理器支持哪个操作吗? 最佳答案 不是直接的答案,但链接页面中的以下片段提供了线索(重点是我的):Notalloperationsaresupportedbyalltargetprocessors.Ifaparticularoperationcannotbeimplementedonthetargetprocessor,awarningwillbegeneratedandacallanexter