summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2022-02-23 11:44:40 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2022-02-23 11:44:40 +0000
commit0f547edbd76814f7a8299f5e1647cd0816276ba8 (patch)
tree52253bf26bb967e929a47109ac04775d098ea28f
parent40af1deff9db7b86532db6957ebdbc0aaff38db1 (diff)
Add seperate error handlers in threads
-rw-r--r--apl9.h1
-rw-r--r--concurrency.c15
-rw-r--r--error.c9
3 files changed, 17 insertions, 8 deletions
diff --git a/apl9.h b/apl9.h
index 51cebfb..e56014b 100644
--- a/apl9.h
+++ b/apl9.h
@@ -237,6 +237,7 @@ struct ThreadData
Mail *lastmail;
int lasterror;
Rune *lasterrormsg;
+ ErrorGuard *globalerrorguard;
QLock lock;
Rendez empty;
};
diff --git a/concurrency.c b/concurrency.c
index d04876d..81ff7b1 100644
--- a/concurrency.c
+++ b/concurrency.c
@@ -117,9 +117,18 @@ newprocfn(void *data)
ThreadData *td = newthreaddata();
void **tdptr = threaddata();
*tdptr = td;
- int done = 1;
- send(sp->setupdone, &done);
- runfunc(sp->func, sp->left, sp->right);
+ ErrorGuard *eg = newerrorguard(mkscalarint(0), nil); /* make a catch-all error guard */
+ if(setjmp(eg->jmp)){
+ 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);
+ runfunc(sp->func, sp->left, sp->right);
+ }
lock(&threadlock);
/* TODO remove thread */
unlock(&threadlock);
diff --git a/error.c b/error.c
index 09f2c32..ee6ffe9 100644
--- a/error.c
+++ b/error.c
@@ -5,18 +5,17 @@
#include "apl9.h"
-ErrorGuard *globalerrorguard;
-
ErrorGuard *
newerrorguard(Array *codes, Statement *guard)
{
+ ThreadData *td = getthreaddata();
DfnFrame *fr = getcurrentdfn();
ErrorGuard *eg = emallocz(sizeof(ErrorGuard), 1);
eg->active = 1;
eg->guard = guard;
if(fr == nil)
- globalerrorguard = eg;
+ td->globalerrorguard = eg;
else{
eg->next = fr->errorguards;
fr->errorguards = eg;
@@ -32,9 +31,9 @@ newerrorguard(Array *codes, Statement *guard)
void
throwerror(Rune *msg, int err)
{
- ErrorGuard *matching = globalerrorguard;
- DfnFrame *frame = getcurrentdfn();
ThreadData *td = getthreaddata();
+ ErrorGuard *matching = td->globalerrorguard;
+ DfnFrame *frame = getcurrentdfn();
td->lasterror = err;
if(td->lasterrormsg)
free(td->lasterrormsg);