waiting for elements

Members allowed to view this conversation


What would be the appropriate way of waiting for elements to appear in a queue?



6 months ago Administrator

A very good and question, which I spent some time trying to do something about, some years ago.

The basic problem is that the queue (and all the data structures) are running in user-mode, no switching to the kernel, which is one of the ways in which they are efficient. You absolutely do -not- want to be switching back to kernel mode to wait for a next element.

Problem then is how -do- you wait?

Turns out there's very little - almost no - support for user-mode waiting.

You can call yield(), but then you're kinda busy waiting.

Or maybe the OS has support for user-mode threads (Windows calls them fibers) and then you can control when threads sleep or run; but that still leaves you with the problem of knowing when a queue element has arrived. There's no user-mode event or semaphore or what-have-you.

So right now there *is* no proper, user-mode solution. You have to go to the OS, and you have to use a kernel-based blocking mechanism, where the sender writes to the queue and then triggers the listener(s) to wake up. Which sucks.

You need to log in or create an account to perform any action on this forum.