|
|
|
|
The problem is a classical problem in multi-threaded code -- a race condition. What you probably expected to happen was:
However, what actually happens is more like:
In other words, Thread A was preempted by Thread B, and then back again, and then again. The result is that Thread A's update is overwritten by Thread B, and the check that you thought was happening is made useless. When you have multiple concurrent activities updating a shared data item, you have to be more careful -- you have to synchronize access to that data item.
|
| The page was last updated February 19, 2008 |