It could be done several ways. Does Linux have Tanenbaum style up/down
semaphores? If not, it shouldn't be too hard to do using pthread_mutex.
Each time an element is put on the event queue, you up the semaphore.
Before getting the dequeue lock on the queue, the thread would down the
semaphore.
At this point, you have a pretty easy model, and all of the hard work is in
implementing the down function. I would say that the semaphore could be
implemented with a lock, a counter, and a queue of pthread_t objects. The
trick is that when you down a semaphore that is already zero, you put the
thread on the queue and have it go to sleep. Then when you up a semaphore
that has sleeping threads, you wake up the first thread.
The problem is that I don't know how to do the whole sleep/wake up thing
with pthreads. It seems as though it could be done condition variables, but
then you still have the thundering herd problem. I suppose that you could
allocate one condition variable per thread, but that doesn't seem very
elegant either.
-- "With a touch more confidence and a liberal helping of ignorance I would have been a famous evangelist." -- Stranger In A Strange Land PLENTY of ignorance at http://www.cs.pdx.edu/~idr- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/