"POSIX threads are a great way to increase the
responsiveness and performance of your code. In this second article
of a three-part series, Daniel Robbins shows you how to protect the
integrity of shared data structures in your threaded code by using
nifty little things called mutexes."
"In my previous article, I talked about threaded code that did
unusual and unexpected things. Two threads each incremented a
global variable twenty times. The variable was supposed to end up
with a value of 40, but ended up with a value of 21 instead. What
happened? The problem occurred because one thread repeatedly
"cancelled out" the increment performed by the other thread. Let's
take a look at some corrected code that uses a mutex to solve the
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.