-
Notifications
You must be signed in to change notification settings - Fork 301
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 usage of pthread_cond_timedwait #491
fix usage of pthread_cond_timedwait #491
Conversation
pthread_cond_timedwait has to be called with a locked mutex using an unlocked mutex is undefined behaviour although it works on many platforms Signed-off-by: Alexander Mohr <[email protected]> Signed-off-by: Alexander Mohr <[email protected]>
this commit makes sure that we do not wait for up to 10s if we missed the signal for the condition variable the first time Signed-off-by: Alexander Mohr <[email protected]>
src/lib/dlt_user.c
Outdated
@@ -3775,7 +3775,9 @@ void dlt_user_housekeeperthread_function(void *ptr) | |||
|
|||
// signal dlt thread to be running | |||
*dlt_housekeeper_running = true; | |||
pthread_mutex_lock(&dlt_housekeeper_running_mutex); |
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 per my understading, the lock does not need to be hold while pthread_cond_signal() is called.
From posix specification:
"The pthread_cond_signal() or pthread_cond_broadcast() functions may be called by a thread whether or not it currently owns the mutex..."
Reference: https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_signal.html
I am fine with the rest of the changes.
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.
Hello @alexmohr ,
i just fixed my finding by myself. If you give me a 👍 , I'll merge the PR
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.
Thanks for fixing it! I did not find the time to do it myself :)
pthread_cond_timedwait has to be called with a locked mutex using an unlocked mutex is undefined behaviour
although it works on many platforms
The program was tested solely for our own use cases, which might differ from yours.
Licensed under Mozilla Public License Version 2.0
Alexander Mohr, [email protected], Mercedes-Benz Tech Innovation GmbH, imprint