From 1529b690da080f2a04d3c476c4e08d388b76c355 Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Sun, 10 Mar 2024 18:59:49 +0200 Subject: [PATCH] Apply the new patch from Davis (#2929) --- dlib/threads/threads_kernel_1.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dlib/threads/threads_kernel_1.h b/dlib/threads/threads_kernel_1.h index 586a21b7e..11acad5a5 100644 --- a/dlib/threads/threads_kernel_1.h +++ b/dlib/threads/threads_kernel_1.h @@ -92,16 +92,22 @@ namespace dlib void wait ( ) const { - std::unique_lock cs(m.cs, std::defer_lock); + std::unique_lock cs(m.cs, std::adopt_lock); cv.wait(cs); + // Make sure we don't actually modify the mutex. Since the calling code will have locked + // it and it should remain locked. + cs.release(); } bool wait_or_timeout ( unsigned long milliseconds ) const { - std::unique_lock cs(m.cs, std::defer_lock); + std::unique_lock cs(m.cs, std::adopt_lock); auto status = cv.wait_until(cs, std::chrono::system_clock::now() + std::chrono::milliseconds(milliseconds)); + // Make sure we don't actually modify the mutex. Since the calling code will have locked + // it and it should remain locked. + cs.release(); return status == std::cv_status::no_timeout; }