* Re: [9fans] alt..?
@ 2000-06-22 15:08 Sape Mullender
0 siblings, 0 replies; 3+ messages in thread
From: Sape Mullender @ 2000-06-22 15:08 UTC (permalink / raw)
To: ishwar, 9fans
I tried that code. It doesn't crash. Neither is it supposed to.
What is strange in the construction
switch(alt(a)) {
case 0:
pval = recvp(a[0].c);
threadprint(1, "alrmproc: request: %d, %x\n", pval->timer,
pval->mine);
break;
default:
threadprint(2, "wow!");
}
is that you receive from a[0].c twice, ignoring the first value
you receive. When alt() returns (zero in the example above) it
will have put the received value in the location pointed to by
a[0].v (pval, in your case). You probably don't want a recvp
call inside the switch on alt().
Sape
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] alt..?
@ 2000-06-22 16:02 Sape Mullender
0 siblings, 0 replies; 3+ messages in thread
From: Sape Mullender @ 2000-06-22 16:02 UTC (permalink / raw)
To: ishwar, 9fans
You were right, there IS a bug associated with CAHNNOBLK.
In line 86 of /sys/src/libthread/channel.c, replace `continue'
with `break'. Sorry about that.
Sape
^ permalink raw reply [flat|nested] 3+ messages in thread
* [9fans] alt..?
@ 2000-06-22 14:06 Ish Rattan
0 siblings, 0 replies; 3+ messages in thread
From: Ish Rattan @ 2000-06-22 14:06 UTC (permalink / raw)
To: 9fans
One more problem. I am trying to translate the `alef' alarmproc example
(from Vol2. Alef User's Guide -- 2nd Ed). The code is given below.
1. When `a[1]' entry is {nil, nil, CHANEND} -- only one message is
recevied on a[0].c
main: chan: 510c8
alrmproc: request: 2, 510c8
main: done
(the first and the third one are lost..)
2. When a[1] is made {nil, nil, CHANNOBLK} --- program does suicide trap..
main: chan: 510c8
wow!8.out 2331: suicide: ...
Any pointers on nature of `alt' will be appreciated.
- ishwar
----
/* Alarm queue scenario, using synchronous and asynchronous
* channels.. */
#include <u.h>
#include <libc.h>
#include <thread.h>
#define STKSIZE (2*2048)
typedef struct alinfo {
int timer;
Channel *mine;
} alinfo;
void alrmproc(void *arg)
{
alinfo *pval;
Alt a[] = { /* c v op */
{nil, &pval, CHANRCV},
{nil, nil, CHANEND},
};
a[0].c = arg;
for(;;) {
switch(alt(a)) {
case 0:
pval = recvp(a[0].c);
threadprint(1, "alrmproc: request: %d, %x\n", pval->timer,
pval->mine);
break;
default:
threadprint(2, "wow!");
}
}
}
void threadmain(int argc, char *argv[])
{
alinfo out;
Channel *cout;
int i;
cout = chancreate(sizeof(alinfo *), 0);
threadprint(1, "main: chan: %x\n", cout);
proccreate(alrmproc, (void *)cout, STKSIZE);
out.mine = cout;
for(i = 0; i< 3; i++) {
out.timer = i+ 1;
sendp(cout, &out);
}
sleep(4000);
threadprint(1, "main: done\n");
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2000-06-22 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-22 15:08 [9fans] alt..? Sape Mullender
-- strict thread matches above, loose matches on Subject: below --
2000-06-22 16:02 Sape Mullender
2000-06-22 14:06 Ish Rattan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).