diff options
author | glenda <glenda@cirno> | 2022-09-09 21:06:16 +0000 |
---|---|---|
committer | glenda <glenda@cirno> | 2022-09-09 21:06:16 +0000 |
commit | d2b44ec9fc7bf4687dae74edfe708395461b5b6e (patch) | |
tree | 8c85d770449928e30c0d4e7eb89460334c16772e /concurrency.c | |
parent | a63358d02ae15ff9a62961d46e58bff26dbab68c (diff) |
Cleanup threads and add a ⎕TASKS system function
Diffstat (limited to 'concurrency.c')
-rw-r--r-- | concurrency.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/concurrency.c b/concurrency.c index be1d62c..ec75474 100644 --- a/concurrency.c +++ b/concurrency.c @@ -195,7 +195,15 @@ newprocfn(void *data) runfunc(sp->func, sp->left, sp->right); } lock(&threadlock); - /* TODO remove thread */ + for(int i = 0; i < nthreads; i++){ + if(threads[i] != td) + continue; + + for(int j = i+1; j < nthreads; j++) + threads[j-1] = threads[j]; + nthreads--; + break; + } unlock(&threadlock); freearray(sp->left); freearray(sp->right); @@ -223,3 +231,41 @@ newthreaddata(void) unlock(&threadlock); return td; } + +Array * +runningtasks(void) +{ + lock(&threadlock); + Array *tasks = allocarray(AtypeInt, 1, nthreads); + tasks->shape[0] = nthreads; + for(int i = 0; i < nthreads; i++) + tasks->intdata[i] = threads[i]->id; + unlock(&threadlock); + return tasks; +} + +Array * +taskproperty(vlong t, vlong p) +{ + ThreadData *td = nil; + Array *res = nil; + lock(&threadlock); + for(int i = 0; i < nthreads && td == nil; i++) + if(threads[i]->id == t) + td = threads[i]; + if(td == nil) + res = mkscalarint(-1); + else + switch(p){ + case 0: + res = mkscalarint(t); /* thread id */ + break; + default: + unlock(&threadlock); + throwerror(L"Invalid task property", EDomain); + break; + } + + unlock(&threadlock); + return res; +}
\ No newline at end of file |