thread.h: Broadcast not signal when waking lock waiters - #24652
thread.h: Broadcast not signal when waking lock waiters#24652khwilliamson wants to merge 1 commit into
Conversation
I would find that counter-intuitive for
Only when one expects to unblock multiple threads. But also: we should probably use |
Better throughput is possible, when a lock is released, by waking all threads waiting for it, instead of just one thread. The POSIX Standard says this.
faf8807 to
654c005
Compare
There are situations where it is better to signal one thread, and ones where it is better to broadcast. We don't know in any given situation which it would be. I think libc could be in a better position to know, but perhaps the cost of record keeping would out weigh any payoff. So is it better to always throttle down the cases where it would be better to do the broadcast, or is it better to be optimistic with the potential negative consekuence of some extra bits of work? I'm thinking it's better to be optimistic that even if there is extra work now, future advances in libc implementations would tilt it the other way in more cases. One case where the read unlocking doing a broadcast would be better could be when you have a bunch of readers waiting for the release of a write lock. Many libc calls want a constant environment during their execution, so this is a fairly common case when somebody is changing it. That thread releases and broadcasts. Only one of those is going to get to execute to lock it again, but very briefly. It might be that this all takes place before any of the other threads are even scheduled, so the original broadcast stands. But if not, should the reader unlocking the mutex do a broadcast or a signal? Based on your comment, I've changed it to just a signal, but I don't know. As far as using
Our code would need to be significantly restructured to not run afoul of that. (And I see no valid reason why an implementation would not to easily be able to handle this case properly. I've seen that too many times, where the implementation takes the easy way out; and anyone who needs to get it to work reliably is forced to compensate, so the cost to society is higher than if the implementation had DTRT) The opposite direction, of holding a read-lock and trying to convert it to write could easily cause deadlock. (A long time ago, I could not type the letter that comes between p and r into text boxes on my browser. Somehow that went away; maybe I found a way around it, maybe it got fixed. But it has just come back, and so I used a 'k' instead above) |
Better throughput is possible, when a lock is released, by waking all threads waiting for it, instead of just one thread. The POSIX Standard says this.