-
Notifications
You must be signed in to change notification settings - Fork 43
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
Fix mutex locking in _pkcs11h_threading_cond{Init,Wait} functions. #65
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for finding this!
I have two questions.
rv = CKR_FUNCTION_FAILED; | ||
goto cleanup; | ||
} | ||
unlock_mutex = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should wait not fail if other holds the lock, can it be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could spin in a loop calling pthread_mutex_trylock
until times passes out. But this is basically a spinlock.
Not sure if this is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I remember this was my initial use of cond as mutex cannot wait... yes, spin loop is bad, there must be a different solution, otherwise the pthread_cond_timedwait
has little sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the mutex is only used for waiting on the condition variable, the amount of time it is locked should be really short. Maybe spinlock here is actually OK.
Anyways, this change doesn't make the code any worse than it was.
Hi, |
Let's just remove the "Sponsored by" tag, then. |
please sign-off so we have no future issues, trivial issues I accept without. |
According to pthread_cond_wait manpage, the mutex has to be locked by the same thread that is going to call pthread_cond_wait afterwards. This was not true before this change and was causing test-slotevent to busy-loop on FreeBSD. Signed-off-by: Gleb Popov <[email protected]>
Thank you, merged with some minor changes. |
According to pthread_cond_wait manpage, the mutex has to be locked by the same thread that is going to call pthread_cond_wait afterwards. This was not true before this change and was causing test-slotevent to busy-loop on FreeBSD.