From 5ede90fa4c1e847df243122693b455c0af69ee24 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Fri, 10 Mar 2023 17:26:04 -0600 Subject: [PATCH] Avoid deadlock in section code. --- link-grammar/dict-atomese/lookup-atomese.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/link-grammar/dict-atomese/lookup-atomese.cc b/link-grammar/dict-atomese/lookup-atomese.cc index fecd4b573..fefc313fa 100644 --- a/link-grammar/dict-atomese/lookup-atomese.cc +++ b/link-grammar/dict-atomese/lookup-atomese.cc @@ -111,6 +111,7 @@ bool as_open(Dictionary dict) { Local* local = new Local; local->stnp = nullptr; + local->pair_dict = nullptr; // If an external atomspace is specified, then use that. if (external_atomspace) @@ -679,8 +680,10 @@ void make_dn(Dictionary dict, Exp* exp, const char* ssc) #define ENCHAIN(ORHEAD,EXP) \ if (nullptr == ORHEAD) \ ORHEAD = (EXP); \ - else \ - ORHEAD = make_or_node(dict->Exp_pool, ORHEAD, (EXP)); + else { \ + std::lock_guard guard(local->dict_mutex); \ + ORHEAD = make_or_node(dict->Exp_pool, ORHEAD, (EXP)); \ + } /// Given a word, return the collection of Dict_nodes holding the /// expressions for that word. @@ -745,13 +748,10 @@ throw FatalErrorException(TRACE_INFO, "Sorry! Not implemented yet! (word=%s)", s Exp* exp = nullptr; - // XXX TODO move this lock so it does not surround AtomSpace - // operations (which are slow, and don't need a lock.) - std::lock_guard guard(local->dict_mutex); - // Create disjuncts consisting entirely of "ANY" links. if (local->any_disjuncts) { + std::lock_guard guard(local->dict_mutex); Exp* any = make_any_exprs(dict, dict->Exp_pool); or_enchain(dict->Exp_pool, exp, any); }