Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel send() condition variable lock ordering #20879

Merged
merged 1 commit into from
Nov 21, 2022

Conversation

zevv
Copy link
Contributor

@zevv zevv commented Nov 19, 2022

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.

@Araq Araq merged commit 79b25a9 into nim-lang:devel Nov 21, 2022
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 79b25a9

Hint: mm: orc; opt: speed; options: -d:release
165158 lines; 11.616s; 614.562MiB peakmem

capocasa pushed a commit to capocasa/Nim that referenced this pull request Mar 31, 2023
narimiran pushed a commit that referenced this pull request Apr 25, 2023
narimiran pushed a commit that referenced this pull request Apr 25, 2023
narimiran pushed a commit that referenced this pull request Apr 25, 2023
narimiran pushed a commit that referenced this pull request Apr 25, 2023
narimiran pushed a commit that referenced this pull request Apr 26, 2023
bung87 pushed a commit to bung87/Nim that referenced this pull request Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants