* more re-work
[mascara-docs.git] / i386 / junos / ucla / src / lab5 / user / pingpongs.c
blob1b615f0c312bb3d76a2cd5b03557b1f11ba6b771
1 // Ping-pong a counter between two shared-memory processes.
2 // Only need to start one of these -- splits into two with sfork.
4 #include <inc/lib.h>
6 uint32_t val;
8 asmlinkage void
9 umain(int argc, char **argv)
11 envid_t who;
12 uint32_t i;
14 i = 0;
15 if ((who = sfork()) != 0) {
16 cprintf("i am %08x; env is %p\n", sys_getenvid(), thisenv);
17 // get the ball rolling
18 cprintf("send 0 from %x to %x\n", sys_getenvid(), who);
19 ipc_send(who, 0, 0, 0);
22 while (1) {
23 ipc_recv(&who, 0, 0);
24 cprintf("%x got %d from %x (env is %p %x)\n", sys_getenvid(), val, who, thisenv, thisenv->env_id);
25 if (val == 10)
26 return;
27 ++val;
28 ipc_send(who, 0, 0, 0);
29 if (val == 10)
30 return;