[quickjs-devel] Re: Bug with JSContext stack_top and multithreading

  • From: Sam Hocevar <sam@xxxxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Wed, 13 Nov 2019 11:27:15 +0100

On Sun, Nov 10, 2019, Koushik Dutta wrote:

I'm using QuickJS in a multithreaded environment, where all access is
synchronized, so only one thread may be executing on the QuickJS runtime at
any given time. This works great, but I had to patch
out js_check_stack_overflow.

js_check_stack_overflow checks the JSContext stack_top (which is set only
at creation) against the current stack pointer. The stack pointer changes,
depending on which thread is being used. The comparison ends up being
erroneous and throwing a stack overflow. This is easily reproducible.

   Just FYI, I ran into a slightly similar issue because my JS context is
constructed on a different thread than the “main” JS thread. My fix was
to add a new void JS_TrackCurrentThread(JSContext *ctx) function that the
user needs to call before any QuickJS call. This works great for me because
despite the multithreaded environment I only have one active JS thread, so
it may or not be ideal for you.
 
Regards,
-- 
Sam.

Other related posts: