草庐IT

atomic_acquire

全部标签

C++ 11 未定义对 `__atomic_store_16' 的引用

这个问题在这里已经有了答案:is_lock_freenotdefinedinstd::atomicingcc4.7.2?(1个回答)关闭8年前。以下代码链接失败:#includestructA{unsignedlonga;unsignedlongb;};structB{voidset(Atmp){_a.store(tmp);}std::atomic_a;};intmain(){Bb;b.set(A());return0;}出现以下错误:/tmp/cc8gyaZM.o:Infunction`std::atomic::store(A,std::memory_order)':dryn.cpp

c++ - 为什么在通知 condition_variable 之前需要获取锁来修改共享的 "atomic"变量

这个问题在这里已经有了答案:Whyistherenowaitfunctionforcondition_variablewhichdoesnotrelockthemutex(1个回答)关闭7个月前。根据cppreference.com:Thethreadthatintendstomodifythevariablehastoacquireastd::mutex(typicallyviastd::lock_guard)performthemodificationwhilethelockisheldexecutenotify_oneornotify_allonthestd::condition

C++ 为什么atomic_load的参数类型是指针而不是引用?

我同意Whentousereferencesvs.pointers中的答案.但是,我想知道为什么C++将atomic_load定义为templateTatomic_load(conststd::atomic*obj)noexcept;^代替templateTatomic_load(conststd::atomic&obj)noexcept;^谁能帮帮我? 最佳答案 我们拥有这些免费函数模板的原因是与C11的源代码兼容性:#ifdef__cplusplus#include#define_Atomic(X)std::atomic#els

c++ - 将 std::condition_variable 与 atomic<bool> 一起使用

有几个关于SO处理原子的问题,以及其他处理std::condition_variable的问题。但是我的问题是我下面的用法是否正确?三个线程,一个ctrl线程在取消暂停其他两个线程之前做准备工作。当工作线程(发送者/接收者)处于紧密的发送/接收循环中时,ctrl线程还能够暂停它们。使用atomic的想法是在未设置暂停bool值的情况下使紧密循环更快。classSomeClass{public://...//Disregardthatdataispublic...std::condition_variablecv;//UDPthreadswillwaitonthiscvuntilallo

c++ - 如果已经被互斥锁保护,我是否需要使用 atomic<>

给定thispost中的代码,实现Semaphore仅使用atomic和mutex.我很好奇自count已经被updateMutex守护,是atomic有必要吗?structSemaphore{intsize;atomiccount;mutexupdateMutex;Semaphore(intn):size(n){count.store(0);}voidaquire(){while(1){while(count>=size){}updateMutex.lock();if(count>=size){updateMutex.unlock();continue;}++count;update

c++ - 如何打印 std::atomic<unsigned int> 的值?

我正在使用std::atomic在我的程序中。如何使用printf打印它的值?如果我只使用%u是行不通的.我知道我可以使用std::cout,但我的程序中到处都是printf电话,我不想更换他们中的每一个。以前我用的是unsignedint而不是std::atomic,所以我只是使用%u在我的printf中的格式字符串中调用,因此打印工作正常。尝试打印std::atomic时遇到的错误现在代替常规unsignedint是:error:format‘%u’expectsargumentoftype‘unsignedint’,butargument2hastype‘std::atomic’

c++ - "atomic"和 "cstdatomic"有什么区别?

有人可以澄清一下包含选项之间的区别吗#include和#inlucde?我猜没有,因为它的行为相同?我问这个是因为在我的debian系统上我只有atomic而在我的kubuntu系统上我有cstdatomic。Debian上的编译器:版本4.7.2(Debian4.7.2-4)Kubuntu上的编译器:版本4.6.3(Ubuntu/Linaro4.6.3-1ubuntu5) 最佳答案 现有的两个答案都是错误的,大多数评论也是如此。不是任何标准中定义的header。它在旧的C++0x草案中定义,但不在最终的C++11标准中,仅是。因此

c++ - 在 C++11 中以无锁方式原子交换两个 std::atomic<T*> 对象?

以下代码是从PARSECbenchmarksuiteforshared-memorymultiprocessors中的模拟退火应用程序中提取的原子指针类的框架。.在该应用程序中,中央数据结构是一个图形(更具体地说,是集成电路的网表)。图中的每个节点都有一个指示其物理位置的属性。该算法产生许多线程,每个线程重复并随机选择两个节点并交换它们的物理位置,如果这样可以为芯片带来更好的路由成本。由于图很大,每个线程都可以选择任意一对节点,唯一可行的解​​决方案是无锁并发数据结构(CDS)。这就是为什么以下AtomicPtr类是至关重要的(它用于以无锁方式自动交换指向两个物理位置对象的指针)。函数

c++ - 什么时候应该使用 std::atomic_compare_exchange_strong?

C++11中有两个原子CAS操作:atomic_compare_exchange_weak和atomic_compare_exchange_strong。根据cppreference:Theweakformsofthefunctionsareallowedtofailspuriously,thatis,actasif*obj!=*expectedeveniftheyareequal.Whenacompare-and-exchangeisinaloop,theweakversionwillyieldbetterperformanceonsomeplatforms.Whenaweakcom

c++ - 为什么允许 std::atomic_{char,schar,etc.} typedef 是 std::atomic<T> 基类的类型定义,而不仅仅是 atomic<T>?

C++11[atomics.types.generic]p7:Thereshallbenamedtypescorrespondingtotheintegralspecializationsofatomic,asspecifiedinTable145,andanamedtypeatomic_boolcorrespondingtothespecifiedatomic.Eachnamedtypeisaeithertypedeftothecorrespondingspecializationorabaseclassofthecorrespondingspecialization.Ifitisa