Is using `std::get` on a `std::tuple` guaranteed to be thread-safe for different values of `I`?

Since std::get has no explicit statements in the specification about its data race properties, we fall back to the default behavior defined in [res.on.data.races]. Specifically, paragraphs 2 and 3 tell the story: A C++ standard library function shall not directly or indirectly access objects (1.10) accessible by threads other than the current thread unless the … Read more

BlockingCollection(T) performance

There are a couple of potential possibilities, here. First, BlockingCollection<T> in the Reactive Extensions is a backport, and not exactly the same as the .NET 4 final version. I wouldn’t be surprised if the performance of this backport differs from .NET 4 RTM (though I haven’t profiled this collection, specifically). Much of the TPL performs … Read more

How do you lazily construct a singleton object thread-safely? [duplicate]

Here’s Meyer’s singleton, a very simple lazily constructed singleton getter: Singleton &Singleton::self() { static Singleton instance; return instance; } This is lazy, and C++11 requires it to be thread-safe. In fact, I believe that at least g++ implements this in a thread-safe manner. So if that’s your target compiler or if you use a compiler … Read more

ConcurrentHashMap read and write locks

I think javadoc answers both your questions: Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove). Retrievals reflect the results of the most recently completed update operations holding upon their onset. For aggregate operations such as putAll and clear, concurrent retrievals may reflect insertion or removal … Read more

What is the difference between synchronized(this) and synchronized method

The two different methods are functionally equivalent. There may be a very small performance difference: At the bytecode level, the synchronized method advertises its need for synchronization as a bit set in the method’s access flag. The JVM looks for this bit flag and synchronizes appropriately. The synchronized block implements its synchronization through a sequence … Read more