В Вс, 19/06/2022 в 10:32 +0000, adr пишет: > On Sun, 19 Jun 2022, andrey100100...@gmail.com wrote: > > No way. All processes must run simultaneously. > > NFN limit cannot be bypassed. > > Yeah, that's why I said it was silly: > > > > The solution is obvious, cancel the process' handlers before it > > > > exits so we don't run out of space. > > > > > > This was really silly... > > The changes I'm testing are not for evading the limit, but for > making the handler managment more efficient and specially to avoid > the case when a process could remove another process' handler from > onnote[]. >
Yes, you were absolutely right, the thread library needs some work. It is impossible to use multiple processes with notes, due to the exhaustion of the NFN limit. as example: --------------------------------------------------------- #include <u.h> #include <libc.h> #include <thread.h> static int handler_alarm(void *, char *msg) { if(strstr(msg, "alarm")){ return 1; } return 0; } static void proc_func(void *c) { Channel *chan = c; int fd; char req[] = "request"; char resp[512], *r = nil; if(threadnotify(handler_alarm, 1) == 0){ fprint(1, "handler not registred\n"); } alarm(2000); if((fd = dial("udp!185.157.221.201!5678", nil, nil, nil)) >= 0){ alarm(0); alarm(2000); if(write(fd, req, strlen(req)) == strlen(req)){ alarm(0); alarm(2000); if(read(fd, resp, sizeof(resp)) > 0){ alarm(0); if((r = malloc(sizeof(resp))) == nil){ sysfatal("malloc error: %r"); } memmove(r, resp, sizeof(resp)); } } close(fd); } alarm(0); send(chan, r); threadexits(nil); } int mainstacksize = 5242880; void threadmain(int argc, char *argv[]) { Channel *chan = nil; char *data = nil; int nproc = 0; ARGBEGIN{ case 'n': nproc = atoi(EARGF(threadexitsall(nil))); break; default: threadexitsall(nil); }ARGEND; if((chan = chancreate(sizeof(char *), 0)) == nil){ sysfatal("channel error: %r"); } for(int j = 0; j < 10 ; j++){ for(int i = 0; i < nproc; i++){ proccreate(proc_func, chan, 10240); } for(int i = 0; i < nproc; i++){ if(data = recvp(chan)){ free(data); } } fprint(1, "j: %d\n", j); } if(nproc) fprint(1, "EXIT with nproc: %d\n", nproc); threadexitsall(nil); } --------------------------------------------------------- cpu% 6.out -n 10 j: 0 j: 1 j: 2 handler not registred handler not registred handler not registred handler not registred handler not registred handler not registred handler not registred and stalled forever... And yes, threadnotify(handler_alarm, 0) in proc_func does not help. I don't know how best to get out of this situation. Probably will have to rewrite the program, so that it does not matter how many processes have fallen. But it's an increase in complexity. Regards, Andrej ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/Tfa6823048ad90a21-M2fc7967213269fe01e89ac5c Delivery options: https://9fans.topicbox.com/groups/9fans/subscription