On Tue, 21 Jun 2022, andrey100100...@gmail.com wrote:

For example, let's remove note.c. You could obtain the same result

Just for clarity, you actually don't need to remove note.c to do
what I said below.

in your example (all processes using the same handler) using atnotify
because the notes are registered to the children when proccreate
uses rfork:

void
threadmain(int argc, char *argv[])
{
        atnotify(handler_alarm, 1);

./5.out | grep end | wc -l
        80

If you have to use a different handler for each processes you can't
use atnotify because of RFMEM, but you can use the syscalls notify
and noted:

#include <u.h>
#include <libc.h>
#include <thread.h>

static void
handler_alarm(void *, char *msg)
{
        if(strstr(msg, "alarm")){
                print("yes");
                noted(NCONT);
                return; /* just in case */
        }
        noted(NDFLT);
}

static void
proc_udp(void *)
{
        char resp[512];
        char req[] = "request";
        int fd;
        notify(handler_alarm);
        if((fd = dial("udp!185.157.221.201!5678", nil, nil, nil)) >=
0){
                if(write(fd, req, strlen(req)) == strlen(req)){
                        fprint(1, "start\n");
                        alarm(2000);
                        read(fd, resp, sizeof(resp));
                        alarm(0);
                        fprint(1, "end\n");
                }
                close(fd);
        }
        threadexits(nil);
}

int mainstacksize = 5242880;

void
threadmain(int argc, char *argv[])
{
        for(int i = 0; i < 80; i++)
                proccreate(proc_udp, nil, 10240);
        sleep(5000);
        threadexitsall(nil);
  }

./5.out | grep end | wc -l
        80

Threadnotify is trying to do an atnotify that works with RFMEM,
but to do that onnote should be allocated to grow or shrink (or
have a size thinking in the maximum number of processes the program
could spawn, not the number of handlers a process could register
as in atnotify), instead of pointers to handlers, it should be an
array of pointers to arrays of handlers allocated by each process.

Now again, does the notes mechanism actually fit in libthread? If
it does it should be fixed, if not removed.


I vote for the fix.
Perhaps the notification is being used somewhere or by someone.



adr.


Regards,
Andrej

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

Reply via email to