On Sun, 19 Jun 2022, adr wrote:
The solution is obvious, cancel the process' handlers before it exits so we don't run out of space.
This was really silly...
Now, is there any reason to not do that in threadexits() when it terminates the process? Shouldn't threadnotify() cancel only the process' handlers? We are sharing onnote[NFN] and the code as it is right now removes the first handler that match the pointer, it can belong to another process.
I ended up playing with this (do not register duplicated handlers, cancel only the notes of the thread's process and cancel all notes when the process exits): /sys/src/libthread/sched.c: [...] if(t == nil){ _threaddebug(DBGSCHED, "all threads gone; exiting"); cancelnotes(p->pid); _schedexit(p); } [...] /sys/src/libthread/note.c [...] int threadnotify(int (*f)(void*, char*), int in) { int i, frompid, topid; int (*from)(void*, char*), (*to)(void*, char*); if(in){ from = nil; frompid = 0; to = f; topid = _threadgetproc()->pid; lock(&onnotelock); for(i=0; i<NFN; i++) if(onnote[i]==to && onnotepid[i]==topid){ unlock(&onnotelock); return i<NFN; } unlock(&onnotelock); }else{ from = f; frompid = _threadgetproc()->pid; to = nil; topid = 0; } lock(&onnotelock); for(i=0; i<NFN; i++) if(onnote[i]==from && onnotepid[i]==frompid){ onnote[i] = to; onnotepid[i] = topid; break; } unlock(&onnotelock); return i<NFN; } void cancelnotes(int pid) { int i; lock(&onnotelock); for(i=0; i<NFN; i++) if(onnotepid[i] == pid){ onnote[i] = nil; onnotepid[i] = 0; } unlock(&onnotelock); return; } /sys/include/thread.h [...] void cancelnotes(int pid); [...] Anyway, I would like to know a real example when it is useful to span a hundred processes using libthread without really exploiting threads at all. I mean, we have been streching things a little here! adr. ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/Tfa6823048ad90a21-M2ce0715ee9e683875392de68 Delivery options: https://9fans.topicbox.com/groups/9fans/subscription