From 759d2d541d943fe95138789477fa6faddf6e3e08 Mon Sep 17 00:00:00 2001 From: glenda Date: Sun, 11 Sep 2022 09:17:43 +0000 Subject: Clone all symbols in scope when spawning a new thread (closures), since the scope may get freed. --- concurrency.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'concurrency.c') diff --git a/concurrency.c b/concurrency.c index 80b9920..b49b43a 100644 --- a/concurrency.c +++ b/concurrency.c @@ -65,6 +65,7 @@ spawnthread(Function f, Array *name, Array *left, Array *right) Channel *setupdone = chancreate(sizeof(int), 0); SpawnData *sp = emalloc(sizeof(SpawnData)); sp->func = dupfunction(f); + sp->func.scope = dupscope(f.scope); sp->name = duparray(name); sp->left = left ? duparray(left) : nil; sp->right = duparray(right); @@ -192,12 +193,6 @@ newprocfn(void *data) ErrorGuard *eg = newerrorguard(mkscalarint(0), nil); /* make a catch-all error guard */ if(setjmp(eg->jmp)) displayerror(); - /* print("Thread %d: %S%S%S\n", - threadid(), - errorstr(td->lasterror), - (td->lasterror && td->lasterrormsg) ? L": " : L"", - td->lasterrormsg ? td->lasterrormsg : L""); - */ else{ int done = 1; send(sp->setupdone, &done); @@ -217,6 +212,7 @@ newprocfn(void *data) freearray(sp->name); freearray(sp->left); freearray(sp->right); + freedfnframe(sp->func.scope, 0); freefunction(sp->func); free(sp); free(td); -- cgit v1.2.3