9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] syscall silently kill processes (fwd)
@ 2022-06-20  6:11 adr
  0 siblings, 0 replies; only message in thread
From: adr @ 2022-06-20  6:11 UTC (permalink / raw)
  To: 9fans

The last mail got screwed, I'm resending this for clarity. 
/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 && in>-2){
                from = nil;
                frompid = 0;
                to = f;
                topid = (in == -1)? -1 : _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 = (in < -1)? -1 : _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;
}

static void
delayednotes(Proc *p, void *v)
{
        int i;
        Note *n;
        int (*fn)(void*, char*);

        if(!p->pending)
                return;

        p->pending = 0;
        for(n=notes; n<enotes; n++){
                if(n->proc == p){
                        for(i=0; i<NFN; i++){
                                if((onnotepid[i]!=p->pid && onnotepid[i]!=-1) || (fn = onnote[i])==nil)
                                        continue;
                                if((*fn)(v, n->s))
                                        break;
[...]
/sys/include/thread.h
[...]
void cancelnotes(int pid);
[...] 

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T5a58cfad5bc60d5c-Mcbab164c50af064e722c9315
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-20  6:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20  6:11 [9fans] syscall silently kill processes (fwd) adr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).