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>
This commit is contained in:
Marco Costalba
2012-01-30 14:09:20 +01:00
parent df31398bb9
commit 51e8efdab5
3 changed files with 38 additions and 47 deletions

View File

@@ -123,12 +123,12 @@ private:
friend struct Thread;
Thread threads[MAX_THREADS + 1]; // Last one is used as a timer
Lock threadsLock;
Lock splitLock;
WaitCondition sleepCond;
Depth minimumSplitDepth;
int maxThreadsPerSplitPoint;
int activeThreads;
bool useSleepingThreads;
WaitCondition sleepCond;
};
extern ThreadsManager Threads;