channel send() condition variable lock ordering #20879
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm trying to get my multi threaded Nim programs running clean with valgrind and thread sanitizers, and this one has been bothering as it always generates a warning from helgrind:
The condition variable in channel send() is signalled without holding the lock; this is techncally not incorrect, but it might lead to spurious wakeups. It could be that the original author ordered the unlock and signal purposely for performance reasons, but I have no way of telling from the code.
Can anyone with more knowledge on this subject look at this?
pthread_cond_signal() documentation states:
"The pthread_cond_broadcast() or pthread_cond_signal() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() have associated with the condition variable during their waits; however, if predictable scheduling behavior is required, then that mutex shall be locked by the thread calling pthread_cond_broadcast() or pthread_cond_signal()."
Funny, but I have no clue what "predictable scheduling behavior" is supposed to mean in this context.