Skip to main content

Posts

Showing posts from October, 2014

C++11 Multithreading - How to avoid race conditions

This article presents how to avoid problem of Race conditions described in this article. As we already know race conditions can occur when two or more threads are trying to invoke some part of code or use the same resource (ex. variable) at the time. That can cause problem of unexpected results. We could see that problem in 'Race conditions' article where two threads was able to modify the same variable value which caused different program output every time we invoked it. In order to avoid that problem we should synchronize operations of our threads using multithreading mechanism called mutexes (abbr. Mutual exclusion ). Mutex is some kind of program flow control lock which which is able to make sure that some part of code locked by itself can be invoked by only one thread at the same time. Such locked part of code is called critical section . When other thread will try to go into critical section it will be blocked and will need to wait until previous thread