В Вс, 19/06/2022 в 10:32 +0000, adr пишет:
> On Sun, 19 Jun 2022, [email protected] 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[].
Ok.
More complete example with thread library:
-------------------------------------------------------------
#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, resp_len;
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((resp_len = 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);
}
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 i = 0; i < nproc; i++){
proccreate(proc_func, chan, 10240);
}
for(int i = 0; i < nproc; i++){
if(data = recvp(chan)){
free(data);
}
}
if(nproc)
fprint(1, "EXIT with nproc: %d\n", nproc);
threadexitsall(nil);
}
-------------------------------------------------------------
cpu% 6.out -n 33
EXIT with nproc: 33
with 34:
cpu% 6.out -n 34
handler not registred
and stalled.
So it is important for me that all processes respond.
Such use, it seems to me, simplifies the program.
Regards,
Andrej
------------------------------------------
9fans: 9fans
Permalink:
https://9fans.topicbox.com/groups/9fans/Tfa6823048ad90a21-Mefb1eb17df6e6f347f6c5bf9
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription