std::mutex performance compared to win32 CRITICAL_SECTION

Please see my updates at the end of the answer, the situation has dramatically changed since Visual Studio 2015. The original answer is below. I made a very simple test and according to my measurements the std::mutex is around 50-70x slower than CRITICAL_SECTION. std::mutex: 18140574us CRITICAL_SECTION: 296874us Edit: After some more tests it turned out … Read more

What “thread safe” really means…In Practical terms

A precise technical definition that everyone agrees on is difficult to come up with. Informally, “thread safe” simply means “is reasonably well-behaved when called from multiple threads”. The object will not crash or produce crazy results when called from multiple threads. The question you actually need to get answered if you intend to do multi-threaded … Read more

Is it OK to ignore InterruptedException if nobody calls interrupt()?

Ignoring a checked exception is never considered to be safe. It may seem okay for you at the moment, but if any other programmer uses your code/API, they should expect the standard behaviour: Which is, the thread “reacting” to an interrupt call, but with whatever “reaction” the thread’s documentation describes. I mean it’s up to … Read more

Initializing ThreadStatic field still causes NullReferenceException

Initializing ThreadStatic fields is a little tricky. In particular there is this caveat: Do not specify initial values for fields marked with ThreadStaticAttribute, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. in the MSDN Docs. What this means is that the thread running when the class … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)