From 21cbcc2235469753ea83f9bac7322f52f938b1d9 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Tue, 19 Nov 2024 10:40:18 +0200 Subject: [PATCH 1/2] More specific assertion for unlocking mutex not owned by the current thread --- stl/src/mutex.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stl/src/mutex.cpp b/stl/src/mutex.cpp index cd44a0044a7..6389e12cada 100644 --- a/stl/src/mutex.cpp +++ b/stl/src/mutex.cpp @@ -147,8 +147,9 @@ static _Thrd_result mtx_do_lock(_Mtx_t mtx, const _timespec64* target) noexcept } _CRTIMP2_PURE _Thrd_result __cdecl _Mtx_unlock(_Mtx_t mtx) noexcept { // unlock mutex + _THREAD_ASSERT(1 <= mtx->_Count, "unlock of unowned mutex"); _THREAD_ASSERT( - 1 <= mtx->_Count && mtx->_Thread_id == static_cast(GetCurrentThreadId()), "unlock of unowned mutex"); + mtx->_Thread_id == static_cast(GetCurrentThreadId()), "unlock of mutex not owned by the current thread"); if (--mtx->_Count == 0) { // leave critical section mtx->_Thread_id = -1; From 1e8afd8c2fdf75eaa2d631887d34d83e4ec60150 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Tue, 19 Nov 2024 11:23:22 +0200 Subject: [PATCH 2/2] Say "greater than zero" clear --- stl/src/mutex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/src/mutex.cpp b/stl/src/mutex.cpp index 6389e12cada..4a35e8c77aa 100644 --- a/stl/src/mutex.cpp +++ b/stl/src/mutex.cpp @@ -147,7 +147,7 @@ static _Thrd_result mtx_do_lock(_Mtx_t mtx, const _timespec64* target) noexcept } _CRTIMP2_PURE _Thrd_result __cdecl _Mtx_unlock(_Mtx_t mtx) noexcept { // unlock mutex - _THREAD_ASSERT(1 <= mtx->_Count, "unlock of unowned mutex"); + _THREAD_ASSERT(mtx->_Count > 0, "unlock of unowned mutex"); _THREAD_ASSERT( mtx->_Thread_id == static_cast(GetCurrentThreadId()), "unlock of mutex not owned by the current thread");