Iandiehard/diag-client-lib

there may be a potential error in file diag-client-lib/lib/utility-support/utility/sync_timer.h

Jimmy-drod opened this issue · 3 comments

there may be a potential error in file diag-client-lib/lib/utility-support/utility/sync_timer.h:

function Start get mutex_lock_, then wait_until(blocked). if function Stop is called to cancel before timeout, it shall not work because mutex_lock_ is occupied in function Start, we can't get mutex_lock_ in function Stop then and it shall stay blocked until mutex_lock_ is released out of scope in function Start after timeout

Thank you for the information.

But as per my understanding , conditional variable in Start() releases the mutex_lock(atomically) after call to wait_until and block the current thread (reference - https://en.cppreference.com/w/cpp/thread/condition_variable).
So, when Stop() is called before timeout happens, Stop() acquires the released mutex and notifies the conditional variable. After Stop() method completes execution, conditional variable in Start() is unblocked , it re-acquires the mutex again and wait_until exits .

Are you facing any deadlock issue in sync_timer ? If yes -> please upload the logs and I can have a look :)

Regards

You are right, I checked cppreference, it does say "Call wait, wait_for, or wait_until on the std::condition_variable (atomically releases the mutex and suspends thread execution until the condition variable is notified, a timeout expires, or a spurious wakeup occurs, then atomically acquires the mutex before returning)", I misunderstood.

thank you for your correction :)

Regards

Close it