On Sat, Jun 03, 2000 at 01:50:54PM +0200, Francis GALIEGUE wrote:
> On Sat, 3 Jun 2000, Matthew Dharm wrote:
>
> > Will a wait queue work in the situation where we do a "wake up" before the
> > thread is actually "sleeping"?
> >
>
> Yes. Waking up an empty queue just returns.
The question is, if I wake up the queue before I sleep on it, do I avoid
sleeping?
See, semaphores give me the following behavior (which is exactly what I
want, except for the task state):
thread1: thread2:
init_LOCKED(sem);
up();
down(); <- no actual waiting
down(); <- now it waits
up(); <- this will wakeup thread2
up(); <- thread2 is allready awake
down(); <- no actual waiting
This works because, as far as I can tell, a semaphore is actually a
counting semaphore -- every time I do an up(), I get to do a down(). And
if I do an up() before I'm blocked on a down(), the down will just return
immediately.
With a waite queue, what happens if I do a wakeup() before the consumer
thread is sleeping()? Does that wakeup get counted somewhere so that when
the thread tries to sleep it will get woken up immediately?
> > And what happens if we do wake-ups faster than we sleep -- do wake-ups have
> > an incrementing counter of some sort, or will we lose the multiple wake-ups?
>
> See above. But I don't really see the problem here: your events are queued
> anyway, so why would this matter?
See above. I'm using a counting semaphore to not only keep me sleeping if
there are no items on the queue, but it also tells me how many items are on
the queue.
Matt Dharm
-- Matthew Dharm Home: mdharm@one-eyed-alien.net Senior Engineer, QCP Inc. Work: mdharm@qcpi.comC: They kicked your ass, didn't they? S: They were cheating! -- The Chief and Stef User Friendly, 11/19/1997
- 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/
This archive was generated by hypermail 2b29 : Wed Jun 07 2000 - 21:00:17 EST