Linux Today: Linux News On Internet Time.

More on LinuxToday

IBM developerWorks: POSIX threads explained, Part 2 - The little things called mutexes

Aug 27, 2000, 17:35 (0 Talkback[s])
(Other stories by Daniel Robbins)


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

[ Thanks to shell-dog for this link. ]

"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 problem...."

Complete Story

Related Stories: