How to implement multithread safe singleton in C++11 without using

C++11 removes the need for manual locking. Concurrent execution shall wait if a static local variable is already being initialized. ยง6.7 [stmt.dcl] p4 If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization. As such, simple have a static function like this: static … Read more

What exactly is std::atomic?

Each instantiation and full specialization of std::atomic<> represents a type that different threads can simultaneously operate on (their instances), without raising undefined behavior: Objects of atomic types are the only C++ objects that are free from data races; that is, if one thread writes to an atomic object while another thread reads from it, the … Read more

Cuda atomics change flag

It looks to me like what you want is a “critical section” in your code. A critical section allows one thread to execute a sequence of instructions while preventing any other thread or threadblock from executing those instructions. A critical section can be used to control access to a memory area, for example, so as … Read more

Django: How can I protect against concurrent modification of database entries

This is how I do optimistic locking in Django: updated = Entry.objects.filter(Q(id=e.id) && Q(version=e.version))\ .update(updated_field=new_value, version=e.version+1) if not updated: raise ConcurrentModificationException() The code listed above can be implemented as a method in Custom Manager. I am making the following assumptions: filter().update() will result in a single database query because filter is lazy a database query … Read more

reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?

There are numerous questions here. Considering them one at a time: reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed? Reference assignment is atomic. Interlocked.Exchange does not do only reference assignment. It does a read of the current value of a variable, stashes away the old value, and assigns the new value to … Read more

What is atomicity in dbms

Re “atomic” In Codd’s original 1969 and 1970 papers he defined relations as having a value for every attribute in a row. The value could be anything, including a relation. This used no notion of “atomic”. He explained that “atomic” meant not relation-valued (ie not table-valued): So far, we have discussed examples of relations which … Read more