Simplify locking in sp_search and sp_search_pv

Avoid to take the lock two times in a tight sequence, the first
in get_next_move() and the second to update sp->moves.

Do all with one lock and so retire the now useless locked version
of get_next_move().

Also fix some theorical race due to comparison sp->bestValue < sp->beta
is done out of lock protection. Finally fix another (harmless but time
waster) race that coudl occur because thread_should_stop() is also
called outside of lock protection.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2010-01-27 17:29:34 +01:00
parent 307909bed8
commit bb968fd42a
4 changed files with 25 additions and 33 deletions

View File

@@ -254,6 +254,8 @@ void MovePicker::score_evasions_or_checks() {
/// are no more moves left.
/// It picks the move with the biggest score from a list of generated moves taking
/// care not to return the tt move if has already been searched previously.
/// Note that this function is not thread safe so should be lock protected by
/// caller when accessed through a shared MovePicker object.
Move MovePicker::get_next_move() {
@@ -343,17 +345,3 @@ Move MovePicker::get_next_move() {
}
}
/// A variant of get_next_move() which takes a lock as a parameter, used to
/// prevent multiple threads from picking the same move at a split point.
Move MovePicker::get_next_move(Lock &lock) {
lock_grab(&lock);
// Note that it is safe to call many times
// get_next_move() when phase == PH_STOP
Move m = get_next_move();
lock_release(&lock);
return m;
}