mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-27 04:26:24 +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
15
src/Makefile
15
src/Makefile
@@ -50,7 +50,9 @@ OBJS = benchmark.o bitbase.o bitboard.o endgame.o evaluate.o main.o \
|
||||
# ----------------------------------------------------------------------------
|
||||
#
|
||||
# debug = yes/no --- -DNDEBUG --- Enable/Disable debug mode
|
||||
# sanitize = yes/no --- (-fsanitize ) --- enable undefined behavior checks
|
||||
# sanitize = undefined/thread/no (-fsanitize )
|
||||
# --- ( undefined ) --- enable undefined behavior checks
|
||||
# --- ( thread ) --- enable threading error checks
|
||||
# optimize = yes/no --- (-O3/-fast etc.) --- Enable/Disable optimizations
|
||||
# arch = (name) --- (-arch) --- Target architecture
|
||||
# bits = 64/32 --- -DIS_64BIT --- 64-/32-bit operating system
|
||||
@@ -202,6 +204,9 @@ ifeq ($(COMP),clang)
|
||||
comp=clang
|
||||
CXX=clang++
|
||||
CXXFLAGS += -pedantic -Wextra -Wshadow
|
||||
ifneq ($(KERNEL),Darwin)
|
||||
LDFLAGS += -latomic
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),armv7)
|
||||
ifeq ($(OS),Android)
|
||||
@@ -261,9 +266,9 @@ else
|
||||
endif
|
||||
|
||||
### 3.2.2 Debugging with undefined behavior sanitizers
|
||||
ifeq ($(sanitize),yes)
|
||||
CXXFLAGS += -g3 -fsanitize=undefined
|
||||
LDFLAGS += -fsanitize=undefined
|
||||
ifneq ($(sanitize),no)
|
||||
CXXFLAGS += -g3 -fsanitize=$(sanitize) -fuse-ld=gold
|
||||
LDFLAGS += -fsanitize=$(sanitize) -fuse-ld=gold
|
||||
endif
|
||||
|
||||
### 3.3 Optimization
|
||||
@@ -496,7 +501,7 @@ config-sanity:
|
||||
@echo "Testing config sanity. If this fails, try 'make help' ..."
|
||||
@echo ""
|
||||
@test "$(debug)" = "yes" || test "$(debug)" = "no"
|
||||
@test "$(sanitize)" = "yes" || test "$(sanitize)" = "no"
|
||||
@test "$(sanitize)" = "undefined" || test "$(sanitize)" = "thread" || test "$(sanitize)" = "no"
|
||||
@test "$(optimize)" = "yes" || test "$(optimize)" = "no"
|
||||
@test "$(arch)" = "any" || test "$(arch)" = "x86_64" || test "$(arch)" = "i386" || \
|
||||
test "$(arch)" = "ppc64" || test "$(arch)" = "ppc" || test "$(arch)" = "armv7"
|
||||
|
||||
Reference in New Issue
Block a user