* more re-work
[mascara-docs.git] / i386 / junos / ucla / src / lab4 / user / pingpong.c
blob1d5ba9336fbcee64563e27375d4bd0f7371fac25
1 // Ping-pong a counter between two processes.
2 // Only need to start one of these -- splits into two with fork.
4 #include <inc/lib.h>
6 asmlinkage void
7 umain(int argc, char **argv)
9 envid_t who;
11 if ((who = fork()) != 0) {
12 // get the ball rolling
13 cprintf("send 0 from %x to %x\n", sys_getenvid(), who);
14 ipc_send(who, 0, 0, 0);
17 while (1) {
18 uint32_t i = ipc_recv(&who, 0, 0);
19 cprintf("%x got %d from %x\n", sys_getenvid(), i, who);
20 if (i == 10)
21 return;
22 i++;
23 ipc_send(who, i, 0, 0);
24 if (i == 10)
25 return;