-
Notifications
You must be signed in to change notification settings - Fork 298
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
Edited mutex lock of dlt_housekeeper_running_mutex #668
Conversation
ranoongs
commented
Jul 28, 2024
The original place of mutex lock was wrong because it didn't protect dlt_housekeeper_running and there was no mutex lock when sending signal.
@michael-methner |
@@ -3827,13 +3827,18 @@ void dlt_user_housekeeperthread_function(void *ptr) | |||
|
|||
pthread_cleanup_push(dlt_user_cleanup_handler, NULL); | |||
|
|||
|
|||
pthread_mutex_lock(&dlt_housekeeper_running_mutex); | |||
|
|||
// signal dlt thread to be running | |||
*dlt_housekeeper_running = true; |
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 @ranoongs
The variable you trying to lock is an atomic type and it is totally free from race data.
Hence I believe we do not need to lock the variable.
Kindly check this point.
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.
Yes, as you said, dlt_housekeeper_running is atomic.
The objective for this commit is to avoid unnecessary pthread_cond_timedwait's timeout.
In rare cases, pthread_cond_timedwait become true right going into while roop.
If this happens, the application who uses DLT library has to wait pthread_cond_timewait's timeout (0.5 sec)
I know 0.5 sec might not be long but, in instruments like cluster this might be a problem.
In the latest codes, pthread_mutex_lock cannot prevent this situation.
Please kindly consider this.
@lti9hc If you look into manual page of pthread_cond_timedwait(), mutex guards are out side the while loop. All the examplary source codes use mutex lock to cover all the critical sections... https://man7.org/linux/man-pages/man3/pthread_cond_timedwait.3p.html If you say 0.5 seconds is not critical, Well... then I have nothing to say. You can just reject it. |
Hello @ranoongs, Thanks for your response quickly, I agree with your point " If the pthread_cond_signal is done 'after' getting into the while loop and 'before' pthread_cond_timedwait, it just waits unnecessary 0.5 seconds" but with your change, what happen if pthread_mutex_lock(&dlt_housekeeper_running_mutex) in dlt_start_threads function will own mutex first? the dlt_user_housekeeperthread_function thread will block until getting mutex |
@lti9hc |
@ranoongs , |
@lti9hc |
the pthread_cond_timedwait() will get timeout The work flow is : .... it may get the log "dlt_log(LOG_CRIT, "Failed to wait for house keeper thread!\n");" |
@lti9hc pthread_mutex_lock(&dlt_housekeeper_running_mutex); .... I share the test result. |
@ranoongs @alexander-mohr could you please take time to have a look at this PR? |
It looks good and merge now Thanks you @ranoongs |