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, sigsuspend, and SIGUSR1.
45 typedef struct Vous Vous;
52 ulong val1; /* value for the sleeper */
53 ulong val2; /* value for the waker */
62 void /*__attribute__((constructor))*/
67 memset(&sa, 0, sizeof sa);
69 sigemptyset(&sa.sa_mask);
70 sigaddset(&sa.sa_mask, SIGUSR1);
72 sa.sa_flags = SA_RESTART;
73 sigaction(SIGUSR1, &sa, nil);
76 static Vous vouspool[2048];
78 static Vous *vousfree;
79 static Vous *voushash[VOUSHASH];
90 }else if(nvousused < nelem(vouspool))
91 v = &vouspool[nvousused++];
93 fprint(2, "rendezvous: out of vous!\n");
113 for(l=&voushash[h], v=*l; v; l=&(*l)->link, v=*l){
131 v->link = voushash[h];
138 rendezvous(ulong tag, ulong val)
147 if((v = findvous(tag)) == nil){
151 * Block USR1, set the handler to interrupt system calls,
152 * unlock the vouslock so our waker can wake us,
159 sigprocmask(SIG_SETMASK, nil, &mask);
160 sigaddset(&mask, SIGUSR1);
161 sigprocmask(SIG_SETMASK, &mask, nil);
163 if(DBG) fprint(2, "%d rv(%lux, %lux) -> s\n", pid, tag, val);
165 sigdelset(&mask, SIGUSR1);
169 * We're awake. Make USR1 not interrupt system calls.
170 * Were we awakened or interrupted?
176 if(DBG) fprint(2, "%d rv(%lux, %lux) -> g %lux\n", pid, tag, val, rval);
178 if(findvous(tag) != v){
179 fprint(2, "rendezvous: interrupted but not found in hash table\n");
183 if(DBG) fprint(2, "%d rv(%lux, %lux) -> g i\n", pid, tag, val);
195 if(DBG) fprint(2, "%d rv(%lux, %lux) -> g %lux, w %d\n", pid, tag, val, rval, vpid);