Fix subtle race with slave allocation
authorMarco Costalba <mcostalba@gmail.com>
Mon, 30 Jan 2012 13:09:20 +0000 (14:09 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 31 Jan 2012 19:19:25 +0000 (20:19 +0100)
commit51e8efdab5f62ebc23e4f7adaea96f619cbca194
tree32c1f6ab037222acebd53467a14b5320b868f9ef
parentdf31398bb91b0e43661176e2f1681617ee64f1ad
Fix subtle race with slave allocation

When allocating a slave we set both is_searching
and splitPoint under lock protection.

Unfortunatly the order in which the variables are
set is not defined. This article was very clarifying:

http://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/

So when in idle loop we test for is_searching and then
access splitPoint, it could happen that splitPoint is still
not updated leading to a possible crash.

Fix the race lock protecting splitPoint access.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/search.cpp
src/thread.cpp
src/thread.h