Skip to content

Commit

Permalink
Avoid deadlock in section code.
Browse files Browse the repository at this point in the history
  • Loading branch information
linas committed Mar 10, 2023
1 parent 0388d78 commit 5ede90f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions link-grammar/dict-atomese/lookup-atomese.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<std::mutex> 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.
Expand Down Expand Up @@ -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<std::mutex> guard(local->dict_mutex);

// Create disjuncts consisting entirely of "ANY" links.
if (local->any_disjuncts)
{
std::lock_guard<std::mutex> guard(local->dict_mutex);
Exp* any = make_any_exprs(dict, dict->Exp_pool);
or_enchain(dict->Exp_pool, exp, any);
}
Expand Down

0 comments on commit 5ede90f

Please sign in to comment.