Entries by Rainer Grimm

The Risks of Mutexes

The usage of mutexes seems extremely simple. There is a critical section in the code that a single thread can only access at any point in time. It’s ensured by a mutex m. The calls m.lock() and m.unlock() guarantee this exclusivity. But the devil is in the details.

Thread Arguments

A thread gets its data by copy or by reference. By default, you should use by copy. Why? In case your thread gets its data by reference, you have to be extremely careful about the lifetime of the arguments.