Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid a race between uci and search threads (II)
limits.ponder was used as a signal between uci and search threads, but is not an atomic variable, leading to the following race as flagged by a sanitized binary. Expect input: ``` spawn ./stockfish send "uci\n" expect "uciok" send "setoption name Ponder value true\n" send "go wtime 4000 btime 4000\n" expect "bestmove" send "position startpos e2e4 d7d5\n" send "go wtime 4000 btime 4000 ponder\n" sleep 0.01 send "ponderhit\n" expect "bestmove" send "quit\n" expect eof ``` Race: ``` WARNING: ThreadSanitizer: data race (pid=7191) Read of size 4 at 0x0000005c2260 by thread T1: #0 MainThread::check_time() src/search.cpp:1488 (stockfish+0x000000454471) #1 search<(<unnamed>::NodeType)0u> src/search.cpp:566 (stockfish+0x0000004594e0) #2 search<(<unnamed>::NodeType)0u> src/search.cpp:997 (stockfish+0x00000045bfb6) #3 search<(<unnamed>::NodeType)0u> src/search.cpp:1006 (stockfish+0x00000045c1a3) #4 search<(<unnamed>::NodeType)1u> src/search.cpp:997 (stockfish+0x000000457658) #5 Thread::search() src/search.cpp:402 (stockfish+0x000000452e28) #6 MainThread::search() src/search.cpp:264 (stockfish+0x000000451c32) #7 Thread::idle_loop() src/thread.cpp:114 (stockfish+0x000000468c90) Previous write of size 4 at 0x0000005c2260 by main thread: #0 UCI::loop(int, char**) src/uci.cpp:193 (stockfish+0x000000473c9b) #1 main src/main.cpp:47 (stockfish+0x000000433322) Location is global 'Search::Limits' of size 88 at 0x0000005c2220 (stockfish+0x0000005c2260) ``` The fix is to add an atomic bool to the threads structure to signal the ponder status, letting Search::Limits to reflect just what was passed to 'go'. No functional change.
- Loading branch information