Skip to content

Commit 1529b69

Browse files
authored
Apply the new patch from Davis (#2929)
1 parent d5909ed commit 1529b69

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

dlib/threads/threads_kernel_1.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,22 @@ namespace dlib
9292
void wait (
9393
) const
9494
{
95-
std::unique_lock<std::mutex> cs(m.cs, std::defer_lock);
95+
std::unique_lock<std::mutex> cs(m.cs, std::adopt_lock);
9696
cv.wait(cs);
97+
// Make sure we don't actually modify the mutex. Since the calling code will have locked
98+
// it and it should remain locked.
99+
cs.release();
97100
}
98101

99102
bool wait_or_timeout (
100103
unsigned long milliseconds
101104
) const
102105
{
103-
std::unique_lock<std::mutex> cs(m.cs, std::defer_lock);
106+
std::unique_lock<std::mutex> cs(m.cs, std::adopt_lock);
104107
auto status = cv.wait_until(cs, std::chrono::system_clock::now() + std::chrono::milliseconds(milliseconds));
108+
// Make sure we don't actually modify the mutex. Since the calling code will have locked
109+
// it and it should remain locked.
110+
cs.release();
105111
return status == std::cv_status::no_timeout;
106112
}
107113

0 commit comments

Comments
 (0)