Skip to content

Commit 00ef1d2

Browse files
committed
fix bug with expired weak_ptr
The cache is not updated if the hash is found, so an expired weak_ptr would block new insertions until evicted.
1 parent 7a57b33 commit 00ef1d2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/search/dag_classic/search.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,21 +2256,22 @@ void SearchWorker::DoBackupUpdateSingleNode(
22562256
} else {
22572257
#ifdef FIX_TT
22582258
auto tt_low_node = entry->lock();
2259-
search_->tt_->Unpin(node_to_process.hash, entry);
22602259
#else
22612260
auto tt_low_node = tt_iter->second.lock();
22622261
#endif
22632262
if (!tt_low_node) {
22642263
#ifdef FIX_TT
2265-
search_->tt_->Insert(node_to_process.hash,
2266-
std::make_unique<std::weak_ptr<LowNode>>(
2267-
node_to_process.tt_low_node));
2264+
// An insert would fail, so update the (expired) entry directly.
2265+
*entry = node_to_process.tt_low_node;
2266+
search_->tt_->Unpin(node_to_process.hash, entry);
22682267
#else
22692268
tt_iter->second = node_to_process.tt_low_node;
22702269
#endif
22712270
node_to_process.node->SetLowNode(node_to_process.tt_low_node);
22722271
} else {
2273-
#ifndef FIX_TT
2272+
#ifdef FIX_TT
2273+
search_->tt_->Unpin(node_to_process.hash, entry);
2274+
#else
22742275
assert(!tt_iter->second.expired());
22752276
#endif
22762277
node_to_process.node->SetLowNode(tt_low_node);

0 commit comments

Comments
 (0)