В Пт, 17/06/2022 в 21:15 +0000, adr пишет: > On Fri, 17 Jun 2022, andrey100100...@gmail.com wrote: > > Seems like noted() call not needed in user code. > > noted() is only needed when using the syscall notify, when using > atnotify() (or threadnotify) you don't need it, as it is said in > notify(2) and you did correctly in your first example. threadnotify > doesn't kill your process if there is no space free in onnote[], > onnotepid[], the handler is not registered, that's all. alarm() > should send the note to the process and the first handler registered > with the note "alarm" should be executed. Your handler checked for > the note and returned non zero, the process should continue. When > read is interrupted, it should return an error, the process should > not be killed. Here is the issue. Comment the read statement and > there will be the same number of "end"s as "start"s. >
Мore clear example, which demonstrate crux of the problem: --------------------------------------------- #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 *) { if(threadnotify(handler_alarm, 1) == 0){ fprint(1, "handler not registred\n"); } alarm(2000); fprint(1, "start\n"); sleep(10000); fprint(1, "end\n"); alarm(0); threadexits(nil); } int mainstacksize = 5242880; void threadmain(int argc, char *argv[]) { for(int i = 0; i < 80; i++){ proccreate(proc_func, nil, 10240); } sleep(5000); threadexitsall(nil); } --------------------------------------------- cpu% 6.out | grep end | wc -l 33 Problem in unregistered handlers. > Note that you could register the handler in threadmain and avoid > completely this issue, but as I said before, something seems wrong > to me here. > I'm don't understand how handler in threadmain would solve the problem. I need in 'alarm' on per process basis. Regards, Andrej ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/Tfa6823048ad90a21-M2bf5df4e0184bdff80c9eee9 Delivery options: https://9fans.topicbox.com/groups/9fans/subscription