Reputation: 1311
I have write the following member function in my class which executes in a seperate thread and it sets the _cancellationRequested to true and execution function which runs in a seperate thread detects that variable and cancel the execution and return. All good in functionality. However I'm getting a TSAN warning as
TSAN WARNING: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread)
at the end of the if block.
bool Sender::CancelRequest()
{
std::unique_lock<std::timed_mutex> lock(_processMutex, std::try_to_lock);
if (!lock.owns_lock())
{
_cancellationRequested = true;
std::unique_lock<std::timed_mutex> timedLock(_processMutex, std::chrono::seconds(30));
if (!timedLock.owns_lock())
{
// Unable to get the lock
return false;
}
return _cancelled;
}
// Cancellation Called without having a request
return false;
}
Please help me in identifying how to fix it.
Upvotes: 1
Views: 109