From d8349f9d0f4eafda145de67330abcc2cb2d9ba56 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 17 Feb 2012 20:38:17 +0100 Subject: [PATCH] Fix a race when extracting PV from TT Because TT table is shared tte->move() could change under our feet, in particular we could validate tte->move() then the move is changed by another thread and we call pos.do_move() with a move different from the original validated one ! This leads to a very rare but reproducible crash once every about 20K games. Signed-off-by: Marco Costalba --- src/search.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 5706b959..d4826946 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1767,14 +1767,14 @@ void RootMove::extract_pv_from_tt(Position& pos) { pos.do_move(m, *st++); while ( (tte = TT.probe(pos.key())) != NULL - && tte->move() != MOVE_NONE - && pos.is_pseudo_legal(tte->move()) - && pos.pl_move_is_legal(tte->move(), pos.pinned_pieces()) + && (m = tte->move()) != MOVE_NONE // Local copy, TT entry could change + && pos.is_pseudo_legal(m) + && pos.pl_move_is_legal(m, pos.pinned_pieces()) && ply < MAX_PLY && (!pos.is_draw() || ply < 2)) { - pv.push_back(tte->move()); - pos.do_move(tte->move(), *st++); + pv.push_back(m); + pos.do_move(m, *st++); ply++; } pv.push_back(MOVE_NONE); -- 2.39.2