stdatomic

What is the (slight) difference on the relaxing atomic rules?

守給你的承諾、 提交于 2020-08-25 10:30:06
问题 After seeing Herb Sutters excellent talk about "atomic weapons" I got a bit confused about the Relaxed Atomics examples. I took with me that an atomic in the C++ Memory Model (SC-DRF = Sequentially Consistent for Data Race Free) does an "acquire" on a load/read. I understand that for a load [and a store] the default is std::memory_order_seq_cst and therefore the two are the same: myatomic.load(); // (1) myatomic.load(std::memory_order_seq_cst); // (2) So far so good, no Relaxed Atomics

Anything in std::atomic is wait-free?

狂风中的少年 提交于 2020-08-24 08:09:29
问题 If T is a C++ fundamental type, and if std::atomic<T>::is_lock_free() returns true , then is there anything in std::atomic<T> that is wait-free (not just lock-free)? Like, load , store , fetch_add , fetch_sub , compare_exchange_weak , and compare_exchange_strong . Can you also answer based on what is specified in the C++ Standard, and what is implemented in Clang and/or GCC (your version of choice). My favorite definitions for lock-free and wait-free are taken from C++ Concurrency in Action

Can an atomic release be “overwritten”?

最后都变了- 提交于 2020-08-05 07:31:31
问题 Say I have atomic<int> i; Thread A performs an atomic store/exchange with memory_order_release. Next, Thread B performs an atomic store with memory_order_release. Thread C performs an atomic fetch_add(0, memory_order_acquire); Does Thread C acquire dependencies from thread A and B or only thread B ? 回答1: Only B (I'm going to assume that by "next" you mean the modification order of the atomic is A -> B -> C so that by [atomics.order]p11 C 's RMW must read the value B wrote). See the note in

Can an atomic release be “overwritten”?

有些话、适合烂在心里 提交于 2020-08-05 07:31:10
问题 Say I have atomic<int> i; Thread A performs an atomic store/exchange with memory_order_release. Next, Thread B performs an atomic store with memory_order_release. Thread C performs an atomic fetch_add(0, memory_order_acquire); Does Thread C acquire dependencies from thread A and B or only thread B ? 回答1: Only B (I'm going to assume that by "next" you mean the modification order of the atomic is A -> B -> C so that by [atomics.order]p11 C 's RMW must read the value B wrote). See the note in

Is it safe to use the Structure dereference(->) operator on the result of std::atomic::load

梦想与她 提交于 2020-08-04 10:21:22
问题 Whilst trying to work with std atomic pointer, I ran into the following. Say I do this: std::atomic<std::string*> myString; // <do fancy stuff with the string... also on other threads> //A can I do this? myString.load()->size() //B can I do this? char myFifthChar = *(myString.load()->c_str() + 5); //C can I do this? char myCharArray[255]; strcpy(myCharArray, myString.load()->c_str()); I'm pretty sure C is illegal because myString might be deleted in the meantime. However I'm unsure about A

Is it safe to use the Structure dereference(->) operator on the result of std::atomic::load

别说谁变了你拦得住时间么 提交于 2020-08-04 10:20:37
问题 Whilst trying to work with std atomic pointer, I ran into the following. Say I do this: std::atomic<std::string*> myString; // <do fancy stuff with the string... also on other threads> //A can I do this? myString.load()->size() //B can I do this? char myFifthChar = *(myString.load()->c_str() + 5); //C can I do this? char myCharArray[255]; strcpy(myCharArray, myString.load()->c_str()); I'm pretty sure C is illegal because myString might be deleted in the meantime. However I'm unsure about A