Code Monkey home page Code Monkey logo

Comments (8)

linas avatar linas commented on June 4, 2024
(gdb) print id
$2 = 65524
(gdb) print d
$3 = (Disjunct *) 0x7ffdce75d660
(gdb) print d->match_id
$4 = 65512

from link-grammar.

linas avatar linas commented on June 4, 2024

Hmm. match_id is a uint16_t and the value here is darned close to the overflow value...

from link-grammar.

ampli avatar ampli commented on June 4, 2024

Hmm. match_id is a uint16_t and the value here is darned close to the overflow value...

I think (not validated by actual debugging but only by code inspection) that this causes the bug.

The purpose of the match_id check is to validate that there are no extra or missing pops up in the match_list stack, and also that no memory corruption occurs in it. To that end, in form_match_list() the id value is grabbed into a local variable lid, so the same value is used for all the match_list entries in the same form_match_list(), not caring whether id has been changed meanwhile by another thread.

But note line 84:

static void push_match_list_element(fast_matcher_t *ctxt, int id, Disjunct *d)
{
if (ctxt->match_list_end >= ctxt->match_list_size)
{
ctxt->match_list_size *= MATCH_LIST_SIZE_INC;
ctxt->match_list = realloc(ctxt->match_list,
ctxt->match_list_size * sizeof(*ctxt->match_list));
}
#ifdef VERIFY_MATCH_LIST
if (id != 0) d->match_id = id;
#endif
ctxt->match_list[ctxt->match_list_end++] = d;
}

When id wrapped around back to 0, then no assignment is done and the previous value of d->match_id persists for all the match_list entries in this form_match_list() invocation (the persisting values are those that existed just near the wrapping around, and thus are close to 65535).

I think the fix is just to remove lines 83-85 (which exist may be due to a code rot).

On the same occasion, it is possible to save a 0 assignment in count.c. However, the code there seems to be a moving target while I'm writing this...

from link-grammar.

linas avatar linas commented on June 4, 2024

What about this:

#ifdef VERIFY_MATCH_LIST
static int id = 0;
int lid = ++id; /* A local copy, for multi-threading support. */
#else
const int lid = 0;
#endif

That looks like a non-atomic increment to me; two threads can ++id at the same time. I believe I have 10 threads running LG at the same time.

from link-grammar.

linas avatar linas commented on June 4, 2024

I just now pushed this: 9f73b37 in the hope that it will narrow down or avoid the problem.

from link-grammar.

linas avatar linas commented on June 4, 2024

I'm confused by this statement:

I think the fix is just to remove lines 83-85 (which exist may be due to a code rot).

If those are removed, then the id does not need to be passed as an argument to any of the functions, and the id is then not set anywhere, so it will always be zero. Did you mean something else?

from link-grammar.

ampli avatar ampli commented on June 4, 2024

I'm confused by this statement:

You are right!
Only the (id != 0) should be removed. The d->match_d = id assignment should be retained.
The #ifdef/#endif should also be retained for future efficiency if VERIFY_MATCH_LIST will not be used.
So it should be:

 #ifdef VERIFY_MATCH_LIST 
 	id->match_id = id; 
 #endif

That looks like a non-atomic increment to me; two threads can ++id at the same time. I believe I have 10 threads running LG at the same time.

No problem with that, since int lid = ++id grabs a local value that is kept constant for the whole same invocation of form_match_list(). The value of the global id can continue to change, but the form_match_list() code doesn't look at it anymore in the same invocation and all the match_list elements in this invocation only use the fixed (per invocation) local copy.

from link-grammar.

linas avatar linas commented on June 4, 2024

Closing. Ran for two days in half-a-dozen threads, no issues arose.

from link-grammar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.