3 rendezvous - user level process synchronization
6 ulong rendezvous(ulong tag, ulong value)
9 The rendezvous system call allows two processes to synchro-
10 nize and exchange a value. In conjunction with the shared
11 memory system calls (see segattach(2) and fork(2)), it
12 enables parallel programs to control their scheduling.
14 Two processes wishing to synchronize call rendezvous with a
15 common tag, typically an address in memory they share. One
16 process will arrive at the rendezvous first; it suspends
17 execution until a second arrives. When a second process
18 meets the rendezvous the value arguments are exchanged
19 between the processes and returned as the result of the
20 respective rendezvous system calls. Both processes are
21 awakened when the rendezvous succeeds.
23 The set of tag values which two processes may use to
24 rendezvous-their tag space-is inherited when a process
25 forks, unless RFREND is set in the argument to rfork; see
28 If a rendezvous is interrupted the return value is ~0, so
29 that value should not be used in normal communication.
31 * This simulates rendezvous with shared memory, pause, and SIGUSR1.
42 typedef struct Vous Vous;
58 void /*__attribute__((constructor))*/
64 static Vous vouspool[2048];
66 static Vous *vousfree;
67 static Vous *voushash[VOUSHASH];
78 }else if(nvousused < nelem(vouspool))
79 v = &vouspool[nvousused++];
95 findvous(ulong tag, ulong val, int pid)
102 for(l=&voushash[h], v=*l; v; l=&(*l)->link, v=*l){
111 v->link = voushash[h];
122 rendezvous(ulong tag, ulong val)
130 v = findvous(tag, val, me);
132 if(DBG)fprint(2, "pid is %d tag %lux, sleeping\n", me, tag);
134 * No rendezvous partner was found; the next guy
135 * through will find v and wake us, so we must go
139 * 1. disable USR1 signals.
140 * 2. unlock v->lk (tells waker okay to signal us).
141 * 3. atomically suspend and enable USR1 signals.
143 * The call to ignusr1() could be done once at
144 * process creation instead of every time through rendezvous.
148 sigprocmask(SIG_SETMASK, NULL, &mask);
149 sigaddset(&mask, SIGUSR1);
150 sigprocmask(SIG_SETMASK, &mask, NULL);
151 sigdelset(&mask, SIGUSR1);
155 if(DBG)fprint(2, "pid is %d, awake\n", me);
159 * Found someone to meet. Wake him:
161 * A. lock v->lk (waits for him to get to his step 2)
164 * He won't get the USR1 until he suspends, which
165 * means it must wake him up (it can't get delivered
173 if(kill(vpid, SIGUSR1) < 0){
174 if(DBG)fprint(2, "pid is %d, kill %d failed: %r\n", me, vpid);