В Вс, 19/06/2022 в 05:01 +0000, adr пишет:
> 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);
> [...]


No way. All processes must run simultaneously.
NFN limit cannot be bypassed.

> 
> 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!
> 

In general, problem not in processes, threads or notes. Problem in
network nature. In the unreliable nature of network communication,
requiring timeouts, packet loss handling, retransmission, etc.

I'm trying to solve it using Plan 9.

In this particular case, I am trying to reduce the total polling time
of, for example, a sensor network by increasing the number of sensors
polled at the same time.

Ready to hear the best solution.

Regards,
Andrej

------------------------------------------
9fans: 9fans
Permalink: 
https://9fans.topicbox.com/groups/9fans/Tfa6823048ad90a21-Mf178309eb46992e6940a5ea4
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

Reply via email to