mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 01:27:16 +08:00
Fix four data races.
the nodes, tbHits, rootDepth and lastInfoTime variables are read by multiple threads, but not declared atomic, leading to data races as found by -fsanitize=thread. This patch fixes this issue. It is based on top of the CI-threading branch (PR #1129), and should fix the corresponding CI error messages. The patch passed an STC check for no regression: http://tests.stockfishchess.org/tests/view/5925d5590ebc59035df34b9f LLR: 2.96 (-2.94,2.94) [-3.00,1.00] Total: 169597 W: 29938 L: 30066 D: 109593 Whereas rootDepth and lastInfoTime are not performance critical, nodes and tbHits are. Indeed, an earlier version using relaxed atomic updates on the latter two variables failed STC testing (http://tests.stockfishchess.org/tests/view/592001700ebc59035df34924), which can be shown to be due to x86-32 (http://tests.stockfishchess.org/tests/view/592330ac0ebc59035df34a89). Indeed, the latter have no instruction to atomically update a 64bit variable. The proposed solution thus uses a variable in Position that is accessed only by one thread, which is copied every few thousand nodes to the shared variable in Thread. No functional change. Closes #1130 Closes #1129
This commit is contained in:
committed by
Joona Kiiski
parent
2c237da546
commit
3cb0200459
@@ -134,6 +134,8 @@ public:
|
||||
void undo_move(Move m);
|
||||
void do_null_move(StateInfo& newSt);
|
||||
void undo_null_move();
|
||||
void increment_nodes();
|
||||
void increment_tbHits();
|
||||
|
||||
// Static Exchange Evaluation
|
||||
bool see_ge(Move m, Value value = VALUE_ZERO) const;
|
||||
@@ -151,6 +153,7 @@ public:
|
||||
bool is_chess960() const;
|
||||
Thread* this_thread() const;
|
||||
uint64_t nodes_searched() const;
|
||||
uint64_t tb_hits() const;
|
||||
bool is_draw(int ply) const;
|
||||
int rule50_count() const;
|
||||
Score psq_score() const;
|
||||
@@ -185,6 +188,7 @@ private:
|
||||
Square castlingRookSquare[CASTLING_RIGHT_NB];
|
||||
Bitboard castlingPath[CASTLING_RIGHT_NB];
|
||||
uint64_t nodes;
|
||||
uint64_t tbHits;
|
||||
int gamePly;
|
||||
Color sideToMove;
|
||||
Thread* thisThread;
|
||||
@@ -353,6 +357,18 @@ inline uint64_t Position::nodes_searched() const {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
inline void Position::increment_nodes() {
|
||||
nodes++;
|
||||
}
|
||||
|
||||
inline uint64_t Position::tb_hits() const {
|
||||
return tbHits;
|
||||
}
|
||||
|
||||
inline void Position::increment_tbHits() {
|
||||
tbHits++;
|
||||
}
|
||||
|
||||
inline bool Position::opposite_bishops() const {
|
||||
return pieceCount[W_BISHOP] == 1
|
||||
&& pieceCount[B_BISHOP] == 1
|
||||
|
||||
Reference in New Issue
Block a user