Skip to content

Commit

Permalink
Hopefully fix a race condition error
Browse files Browse the repository at this point in the history
  • Loading branch information
tewalds committed Dec 18, 2010
1 parent ce707ea commit e427a47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 8 additions & 13 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ Player::Node * Player::genmove(double time, int maxruns){

Time starttime;

Timer timer;
if(time > 0)
timer.set(time, bind(&Player::timedout, this));
stop_threads();

int runs = 0;
for(unsigned int i = 0; i < threads.size(); i++){
Expand All @@ -84,24 +82,21 @@ Player::Node * Player::genmove(double time, int maxruns){
if(runs)
logerr("Pondered " + to_str(runs) + " runs\n");


//let them run!
if(threadstate == Thread_Wait_Start || threadstate == Thread_Wait_End){
threadstate = Thread_Running;
runbarrier.wait();
}
start_threads();

assert(threadstate == Thread_Running);
Timer timer;
if(time > 0)
timer.set(time - (Time() - starttime), bind(&Player::timedout, this));

//wait for the timer to stop them
runbarrier.wait();
CAS(threadstate, Thread_Wait_End, Thread_Wait_Start);

assert(threadstate == Thread_Wait_Start);

if(ponder && root.outcome < 0){
runbarrier.wait();
assert(threadstate == Thread_Running);
}
if(ponder && root.outcome < 0)
start_threads();

time_used = Time() - starttime;

Expand Down
2 changes: 2 additions & 0 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,14 @@ class Player {
timedout();
runbarrier.wait();
CAS(threadstate, Thread_Wait_End, Thread_Wait_Start);
assert(threadstate == Thread_Wait_Start);
}
}

void start_threads(){
assert(threadstate == Thread_Wait_Start);
runbarrier.wait();
CAS(threadstate, Thread_Wait_Start, Thread_Running);
}

void reset_threads(){ //start and end with threadstate = Thread_Wait_Start
Expand Down

0 comments on commit e427a47

Please sign in to comment.