9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: adr <adr@SDF.ORG>
To: 9fans@9fans.net
Subject: Re: [9fans] syscall silently kill processes (fwd)
Date: Mon, 20 Jun 2022 06:11:05 +0000 (UTC)	[thread overview]
Message-ID: <8c4c3084-7c87-e228-f791-69b14675d9b0@SDF.ORG> (raw)

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

                 reply	other threads:[~2022-06-20  6:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c4c3084-7c87-e228-f791-69b14675d9b0@SDF.ORG \
    --to=adr@sdf.org \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).