> where did this go?

Based on the discussions on this thread so far, and on 
https://github.com/libuv/libuv/pull/790
I'd like to propose the following diff:

Index: rthread.h
===================================================================
RCS file: /cvs/src/lib/librthread/rthread.h,v
retrieving revision 1.56
diff -r1.56 rthread.h
144c144,145
-       int sofar;
+       int in;
+       int out;
Index: rthread_barrier.c
===================================================================
RCS file: /cvs/src/lib/librthread/rthread_barrier.c,v
retrieving revision 1.2
diff -r1.2 rthread_barrier.c
71a72
+         int rc;
76a78,80
+         if (rc = pthread_mutex_lock(&(*barrier)->mutex))
+                 return (rc);
+ 
79c83,84
-       if (b->sofar > 0)
+       if (b->out > 0 || b->in > 0) {
+                 pthread_mutex_unlock(&b->mutex);
80a86
+         }
82a89
+         pthread_mutex_unlock(&b->mutex);
106,108c113,116
-       _rthread_debug(6, "sofar: %d, threshold: %d\n", b->sofar, b->threshold);
-       if (++b->sofar == b->threshold) {
-               b->sofar = 0;
+       _rthread_debug(6, "in: %d, threshold: %d\n", b->in, b->threshold);
+       if (++b->in == b->threshold) {
+                 b->out = b->in - 1;
+               b->in = 0;
110c118
-               if ((rc = pthread_cond_broadcast(&b->cond)))
+               if ((rc = pthread_cond_signal(&b->cond)))
120a129,131
+                 b->out--; /* mark thread exit */
+               if ((rc = pthread_cond_signal(&b->cond)))
+                       goto err;

This is pretty much identical to what Paul suggested, but with a blocking call 
to pthread_mutex_lock in _destroy,
as I really think this is the semantics programmers expect, and I it looks to 
me like this is what freeBSD does,
although I don't really understand their code completely.

I also changed pthread_cond_broadcast to pthread_cond_signal, as pointed out by 
bnoordhuis in the linked thread
on github, it's more efficient to avoid waking up threads that will immediately 
start blocking on a mutex again.

I apologise in advance if the diff appears strange, I don't really know how to 
get cvs to do what I want.



Reply via email to