On Mon, 20 Oct 2008, David M. Lloyd wrote:
On 10/20/2008 06:08 PM, david@xxxxxxx wrote:I've suggested that, but the changes nessasary to support that mode of operation are very invasive, and so not an option in the near/medium term.in the case I'm looking at there are two (or more) threads running with one message queue in the center.
'input threads' are grabbing the lock to add messages to the queue
'output threads' are grabbing the lock to remove messages from the queue
the programmer is doing a pthread_yield() after each message is processed in an attempt to help fairness (he initially added it in when he started seeing starvation on single-core systems)
what should he be doing instead?
If you're seeing starvation, to me that's a good indicator that the granularity of queue items are too small... probably there'd be an overall benefit of grabbing more things at once from the queue.
in the meantime is there something better than sched_yield() that should be happening
the sched_yield is an attempt to have the secretary pause once in a while and check to see if the other line has someone waiting.
from looking at the software running, it doesn't seem to work very well. I've also suggested investigating lockless algorithms for the queue, but that is also a lot of high-risk (but high-reward) work. what else can be done to make a mutex more fair?