Are basic C / C ++ types atomic?

Are C/C++ fundamental types, like int, double, etc., atomic, e.g. threadsafe? Are they free from data races; that is, if one thread writes to an object of such a type while another thread reads from it, is the behavior well-defined? If not, does it d

Initialization of an atomic flag in a mallocalised structure

I'm trying to use atomics in C on FreeBSD 10.1 Release with clang 3.6.1, however when I try to compile a program using ATOMIC_FLAG_INIT on a atomic_flag variable in a struct I get error: expected expression. Here is the program I am trying to compile

Why my message queue without lock segfault :(?

As a purely mental exercise I'm trying to get this to work without locks or mutexes. The idea is that when the consumer thread is reading/executing messages it atomically swaps which std::vector the producer thread uses for writes. Is this possible?

Adding the contents of a text file to another file in C ++

How can you open a text file and append all its lines to another text file in C++? I find mostly solutions for separate reading from a file to a string, and writing from a string to a file. Can this elegantly be combined? It is not always given that

Atomic operations for a double-link list without locking

I am writing a lock-free doubly linked list based on these papers: "Efficient and Reliable Lock-Free Memory Reclamation Based on Reference Counting" Anders Gidenstam,Member, IEEE,Marina Papatriantafilou, H˚ akan Sundell and Philippas Tsigas &quo

Why is ATOMIC_FLAG_INIT wrong?

In C++11 there is the std::atomic_flag that is useful for thread loops: static std::atomic_flag s_done(ATOMIC_FLAG_INIT); void ThreadMain() { while (s_done.test_and_set()) { // returns current value of s_done and sets to true // do some stuff in a th

Lifting non-atomic charges by acquiring atomic charges

I was under the impression that memory loads could not be hoisted above an acquiring load in the C++11 memory model. However looking at the code that gcc 4.8 produces that only seems to be true for other atomic loads, not all of memory. If that's tru

Why are atomic operations considered safe for threads?

How are atomic operations made thread-safe? I've read about the subject in Wikipedia's article on thread-safety. But the article didn't really explain the process behind the scenes. In other words, why can't an "atomic" operation executed by a t

Requirements for std :: thread :: id. Can it be atomized?

The standard says: "An object of type thread::id provides... a single distinct value for all thread objects that do not represent a thread of execution". Is that a single/distinct value with regard to operator==, or is it the actual bitwise-sing

Atomic types and threads

this is the next step after this topic: Modifying data in threads class Nginx_sender { private: std::atomic_int data; boost::mutex mMutex; void SendMessage(const std::string &msg) { mMutex.lock(); data++; mMutex.unlock(); std::cout << "DATA

Are these CPU operations the same?

Consider the following two cpu operations: sum = 1 + 1 + 1 + 1 + 1 + 1+ 1+......n times and sum = 1 * n Now I want to know that weather these two operations are different in terms of complexity and cpu time. Also can I consider these as atomic operat

Why should I explicitly do an atomic operation?

Consider the following code: int x=0; #pragma omp parallel num_threads(4) default(none) shared(x) { for(int i=0; i<1000; ++i) x++; } cout << x << endl; The expected out put is 4000. However what I usually see is something between 2500-3500.

Atomic access to shared memory

I have a shared memory between multiple processes that interpets the memory in a certain way. Ex: DataBlock { int counter; double value1; double ... } What I want is for the counter to be updated/incremented atomically. And for a memory release to ha

Does String s = & ldquo; foobar & rdquo; atomic?

Is String s = "foobar"; atomic? Assigning a object-reference should be, but I'm no really sure. Thanks.Yes. All reference assignments are atomic in java. Just note that a composite statement like String s = new String("foobar") is not

MongoDB: atomically random element

Is there a way to atomically pop (remove and retrieve) a random element with MongoDB - like Redis's SPOP? I've read the RandomAttribute tutorial but now I need to make sure that the element is also removed when fetched, and this must be done atomical

Objective-C: Atomic default for scalar properties?

A friend told me that the @property default for scalar properties (BOOL, NSInteger, etc.) is nonatomic. I.e., @property BOOL followVenmo; defaults to @property (nonatomic) BOOL followVenmo; But, I was always under the impression that the default is a

Atomic bed in C

According to Are C++ Reads and Writes of an int Atomic?, due to issues of processor caching, reads of ints (and thusly pointers--or so I assume) are not atomic in C. So, my question is is there some assembly that I could use to make the read atomic,

How to make the full text history in Django?

I'd like to have the full history of a large text field edited by users, stored using Django. I've seen the projects: Django Full History (Google Code) Django ModelHistory, and Django FullHistory I've a special use-case that probably falls outside th

Is this C ++ implementation compatible with an Atomic float?

Edit: The code here still has some bugs in it, and it could do better in the performance department, but instead of trying to fix this, for the record I took the problem over to the Intel discussion groups and got lots of great feedback, and if all g