1. 2
  1.  

  2. 3

    Came across this reading the other post about the Linux kernel and thought it was worth calling out. A few years old, but still completely relevant.

    A simpler summary would be: if you are (in C) talking to an interpreter with a GC, make damn sure what you are doing is visible to that GC. Your C code lives outside the VM which is where the GC usually looks for things. The ruby GC tries, but ultimately, fails to accommodate this by scanning the C stack too.

    I’ve run into this bug in lots of languages. tiny scheme had exactly this bug in some core functionality that would trigger if you triggered a GC at just the wrong moment.

    In terms of solutions, I really like what lua does. You talk to the VM through a separate (not C) stack. The API makes it downright hard to have a reference to something that isn’t “published”. For example, all the table (array) manipulation functions work through this stack. It’s not possible to create a table and keep a reference to it in C code that’s invisible to the GC. Also makes the GC more portable because it doesn’t even attempt to scan the C stack.