From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <5.2.0.9.0.20021231213353.00a88ec0@pop.noos.fr> To: 9fans@cse.psu.edu From: Philippe Anel Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: [9fans] libthread help ... Date: Tue, 31 Dec 2002 21:48:52 +0100 Topicbox-Message-UUID: 3a58b912-eacb-11e9-9e20-41e7f4b1d025 Hi, The following program doesn't work when the user hits the "exit" entry of the menu (by clicking the button 2). It is derived from /sys/src/libthread/example.c [which doesn't compile]. According to acid, all procs are waiting a rendezvous: At pc:0x00011aa8:rendezvous+0x7 /sys/src/libc/9syscall/rendezvous.s:5 rendezvous() /sys/src/libc/9syscall/rendezvous.s:3 called from runthread+0x83 /sys/src/libthread/sched.c:127 runthread(p=0x00037dd8) /sys/src/libthread/sched.c:115 called from _sched+0x99 /sys/src/libthread/sched.c:96 _sched() /sys/src/libthread/sched.c:81 called from _schedinit+0x1a4 /sys/src/libthread/sched.c:77 _schedinit(arg=0x00037dd8) /sys/src/libthread/sched.c:27 called from main+0x2a /sys/src/libthread/main.c:32 main(argc=0x00000001,argv=0x7fffefec) /sys/src/libthread/main.c:22 called from _main+0x31 /sys/src/libc/386/main9.s:16 Any idea why ? Philippe, Happy new year. ---------------------------------------------- #include #include #include #include #include #include enum { STACKSIZE = 2048, }; void clockproc(void *arg) { int t, pid; Channel *c; pid = getpid(); c = arg; for(t=0;; t++){ sleep(1000); fprint(2, "[%d]clock->%d\n", pid, t); sendul(c, t); fprint(2, "[%d]clock->sendul\n", pid); } } struct mh { Mousectl *mctl; Channel *cmd; Channel *res; }; void menuhitproc(void *arg) { struct mh *marg; int t, pid; char *items[] = { "exit", nil }; Menu menu = { items, nil, 0 }; pid = getpid(); marg = arg; for (;;) { t = recvul(marg->cmd); t = menuhit(t, marg->mctl, &menu, nil); fprint(2, "[%d]menuhit->%d\n", pid, t); sendul(marg->res, t); fprint(2, "[%d]menu->sendul\n", pid); } } void threadmain(int argc, char *argv[]) { int t, item; Mousectl *mctl; Alt a[] = { // c v op {nil, nil, CHANRCV}, // 0: mouse {nil, nil, CHANRCV}, // 1: resize {nil, &t, CHANRCV}, // 2: clock {nil, &item, CHANRCV}, // 3: menuhit {nil, nil, CHANEND}, }; struct mh marg; int pid; USED(argc); USED(argv); initdraw(0, 0, "frame"); // create mouse event channel and process mctl = initmouse(0, screen); a[0].c = mctl->c; a[1].c = mctl->resizec; // create clock event channel and process a[2].c = chancreate(sizeof(ulong), 0); proccreate(clockproc, a[2].c, STACKSIZE); // create menuhit channel and process a[3].c = chancreate(sizeof(ulong), 0); marg.mctl = mctl; marg.cmd = chancreate(sizeof(ulong), 0); marg.res = a[3].c; proccreate(menuhitproc, &marg, STACKSIZE); pid = getpid(); for(;;){ fprint(2, "[%d]main->alt\n", pid); switch(alt(a)){ case 0: // mouse event if (mctl->buttons & 2) { sendul(marg.cmd, 2); fprint(2, "[%d]main->sendul\n", pid); } if (mctl->buttons & 4) threadexitsall(nil); fprint(2, "[%d]main->click\n", pid); break; case 1: // resize event fprint(2, "[%d]main->resize\n", pid); break; case 2: // clock event fprint(2, "[%d]main->tic\n", pid); break; case 3: // menu event fprint(2, "[%d]main->menu->%d\n", pid, item); break; default: sysfatal("can't happen"); } } } ---------------------------------------------- Here is the log with libthread compiled with : _threaddebuglevel = DBGAPPL | DBGSCHED | DBGCHAN | DBGREND | DBGNOTE | DBGEXEC; ---------------------------------------------- noproc create thread -1.1 name threadmain noproc readying -1.1 2211._ top of schedinit, _threadexitsallstatus=0 2211._ running 2211.1 2211.1 chancreate 35658 2211.1 chancreate 362d8 2211.1 create thread -1.2 name 2211.1 readying -1.2 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ readying 2211.1 2211._ running 2211.1 2212._ top of schedinit, _threadexitsallstatus=0 2211.1 chancreate 37d58 2212._ running 2212.2 2211.1 create thread -1.3 name 2211.1 readying -1.3 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ readying 2211.1 2211._ running 2211.1 2213._ top of schedinit, _threadexitsallstatus=0 2211.1 chancreate 39018 2213._ running 2213.3 2211.1 chancreate 39058 2211.1 create thread -1.4 name 2211.1 readying -1.4 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ readying 2211.1 2214._ top of schedinit, _threadexitsallstatus=0 2211._ running 2211.1 2214._ running 2214.4 [2211]main->alt 2214.4 Queuing alt 3a370 on channel 39058 2214.4 Rendezvous for tag 238412 2211.1 Queuing alt 23318 on channel 35658 2214.4 pausing, state=Dead 2211.1 Queuing alt 2332c on channel 362d8 2214.4 top of schedinit, _threadexitsallstatus=0 2211.1 Queuing alt 23340 on channel 37d58 2214._ sleeping for more work 2211.1 Queuing alt 23354 on channel 39018 2211.1 Rendezvous for tag 144096 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ sleeping for more work [2213]clock->0 2213.3 can rendez alt 38f24 chan 37d58 2213.3 rendez send alt 38f24 chan 37d58 alt 23340 2213.3 unlocking the chanlock 2213.3 chanlock is 0 2213.3 Rendezvous with thread 2211.1 2213.3 readying 2211.1 2213.3 waking process 2211 2213.3 pausing, state=Dead 2211._ running 2211.1 2213.3 top of schedinit, _threadexitsallstatus=0 2211.1 Woke after rendezvous; val is 0 2213._ readying 2213.3 2211.1 Dequeuing alt 23318 from channel 35658 2213._ running 2213.3 2211.1 Dequeuing alt 2332c from channel 362d8 [2213]clock->sendul 2211.1 Dequeuing alt 23340 from channel 37d58 2211.1 Dequeuing alt 23354 from channel 39018 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ readying 2211.1 2211._ running 2211.1 [2211]main->tic [2211]main->alt 2211.1 Queuing alt 23318 on channel 35658 2211.1 Queuing alt 2332c on channel 362d8 2211.1 Queuing alt 23340 on channel 37d58 2211.1 Queuing alt 23354 on channel 39018 2211.1 Rendezvous for tag 144096 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ sleeping for more work 2212.2 can rendez alt 37c64 chan 35658 2212.2 rendez send alt 37c64 chan 35658 alt 23318 2212.2 unlocking the chanlock 2212.2 chanlock is 0 2212.2 Rendezvous with thread 2211.1 2212.2 readying 2211.1 2212.2 waking process 2211 2212.2 pausing, state=Dead 2211._ running 2211.1 2212.2 top of schedinit, _threadexitsallstatus=0 2211.1 Woke after rendezvous; val is 0 2212._ readying 2212.2 2211.1 Dequeuing alt 23318 from channel 35658 2212._ running 2212.2 2211.1 Dequeuing alt 2332c from channel 362d8 2211.1 Dequeuing alt 23340 from channel 37d58 2211.1 Dequeuing alt 23354 from channel 39018 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ readying 2211.1 2211._ running 2211.1 2211.1 can rendez alt 23298 chan 39058 2211.1 rendez send alt 23298 chan 39058 alt 3a370 2211.1 unlocking the chanlock 2211.1 chanlock is 0 2211.1 Rendezvous with thread 2214.4 2211.1 readying 2214.4 2211.1 waking process 2214 2211.1 pausing, state=Dead 2214._ running 2214.4 2211.1 top of schedinit, _threadexitsallstatus=0 2214.4 Woke after rendezvous; val is 0 2211._ readying 2211.1 2214.4 Dequeuing alt 3a370 from channel 39058 2211._ running 2211.1 2214.4 pausing, state=Dead [2211]main->sendul 2214.4 top of schedinit, _threadexitsallstatus=0 [2211]main->click 2214._ readying 2214.4 [2211]main->alt 2214._ running 2214.4 2211.1 Queuing alt 23318 on channel 35658 2211.1 Queuing alt 2332c on channel 362d8 2211.1 Queuing alt 23340 on channel 37d58 2211.1 Queuing alt 23354 on channel 39018 2211.1 Rendezvous for tag 144096 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ sleeping for more work 2214.4 Queuing alt 3a26c on channel 35658 2214.4 Rendezvous for tag 238152 2212.2 can rendez alt 37c64 chan 35658 2214.4 pausing, state=Dead 2212.2 rendez send alt 37c64 chan 35658 alt 3a26c 2214.4 top of schedinit, _threadexitsallstatus=0 2212.2 unlocking the chanlock 2214._ sleeping for more work 2212.2 chanlock is 0 2212.2 Rendezvous with thread 2214.4 2212.2 readying 2214.4 2212.2 waking process 2214 2212.2 pausing, state=Dead 2214._ running 2214.4 2212.2 top of schedinit, _threadexitsallstatus=0 2214.4 Woke after rendezvous; val is 0 2212._ readying 2212.2 2214.4 Dequeuing alt 3a26c from channel 35658 2212._ running 2212.2 2214.4 pausing, state=Dead 2214.4 top of schedinit, _threadexitsallstatus=0 2214._ readying 2214.4 2214._ running 2214.4 2214.4 Queuing alt 3a26c on channel 35658 2214.4 Rendezvous for tag 238152 2214.4 pausing, state=Dead 2214.4 top of schedinit, _threadexitsallstatus=0 2214._ sleeping for more work 2212.2 can rendez alt 37c64 chan 35658 2212.2 rendez send alt 37c64 chan 35658 alt 23318 2212.2 unlocking the chanlock 2212.2 chanlock is 0 2212.2 Rendezvous with thread 2211.1 2212.2 readying 2211.1 2212.2 waking process 2211 2212.2 pausing, state=Dead 2211._ running 2211.1 2212.2 top of schedinit, _threadexitsallstatus=0 2211.1 Woke after rendezvous; val is 0 2212._ readying 2212.2 2211.1 Dequeuing alt 23318 from channel 35658 2212._ running 2212.2 2211.1 Dequeuing alt 2332c from channel 362d8 2211.1 Dequeuing alt 23340 from channel 37d58 2211.1 Dequeuing alt 23354 from channel 39018 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ readying 2211.1 2211._ running 2211.1 2211.1 Queuing alt 23298 on channel 39058 2211.1 Rendezvous for tag 143988 2211.1 pausing, state=Dead 2211.1 top of schedinit, _threadexitsallstatus=0 2211._ sleeping for more work [2213]clock->1 2213.3 Queuing alt 38f24 on channel 37d58 2213.3 Rendezvous for tag 233216 2213.3 pausing, state=Dead 2213.3 top of schedinit, _threadexitsallstatus=0 2213._ sleeping for more work 2212.2 can rendez alt 37c64 chan 35658 2212.2 rendez send alt 37c64 chan 35658 alt 3a26c 2212.2 unlocking the chanlock 2212.2 chanlock is 0 2212.2 Rendezvous with thread 2214.4 2212.2 readying 2214.4 2212.2 waking process 2214 2212.2 pausing, state=Dead 2214._ running 2214.4 2212.2 top of schedinit, _threadexitsallstatus=0 2214.4 Woke after rendezvous; val is 0 2212._ readying 2212.2 2214.4 Dequeuing alt 3a26c from channel 35658 2212._ running 2212.2 2214.4 pausing, state=Dead 2214.4 top of schedinit, _threadexitsallstatus=0 2214._ readying 2214.4 2214._ running 2214.4 [2214]menuhit->0 2214.4 Queuing alt 3a378 on channel 39018 2214.4 Rendezvous for tag 238420 2214.4 pausing, state=Dead 2214.4 top of schedinit, _threadexitsallstatus=0 2214._ sleeping for more work 2212.2 Queuing alt 37c64 on channel 35658 2212.2 Rendezvous for tag 228416 2212.2 pausing, state=Dead 2212.2 top of schedinit, _threadexitsallstatus=0 2212._ sleeping for more work 2211._ Got note hangup 2213._ Got note hangup 2212._ Got note hangup 2214._ Got note hangup 2211._ Unhandled note hangup, proc 20998 2213._ Unhandled note hangup, proc 37d98 2212._ Unhandled note hangup, proc 36318 2214._ Unhandled note hangup, proc 39098