diff options
| author | IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com> | 2023-01-19 15:57:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-19 16:57:29 +0200 |
| commit | f38fd388f8446b62945df4d2bfbcff350955bbce (patch) | |
| tree | 4020c7590990bfc418fd5a01be6e66f475ce1f1c /lib/std/Thread/Condition.zig | |
| parent | 116b7708099846e9ad789514504341b29bcce99c (diff) | |
| download | zig-f38fd388f8446b62945df4d2bfbcff350955bbce.tar.gz zig-f38fd388f8446b62945df4d2bfbcff350955bbce.zip | |
Mutex deadlock detection in debug
Add a debug implementation to Mutex that detects deadlocks caused by calling lock twice in a single thread.
Diffstat (limited to 'lib/std/Thread/Condition.zig')
| -rw-r--r-- | lib/std/Thread/Condition.zig | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig index 70ad0728eb..ab75a0e5e2 100644 --- a/lib/std/Thread/Condition.zig +++ b/lib/std/Thread/Condition.zig @@ -161,12 +161,20 @@ const WindowsImpl = struct { } } + if (comptime builtin.mode == .Debug) { + // The internal state of the DebugMutex needs to be handled here as well. + mutex.impl.locking_thread.store(0, .Unordered); + } const rc = os.windows.kernel32.SleepConditionVariableSRW( &self.condition, - &mutex.impl.srwlock, + if (comptime builtin.mode == .Debug) &mutex.impl.impl.srwlock else &mutex.impl.srwlock, timeout_ms, 0, // the srwlock was assumed to acquired in exclusive mode not shared ); + if (comptime builtin.mode == .Debug) { + // The internal state of the DebugMutex needs to be handled here as well. + mutex.impl.locking_thread.store(std.Thread.getCurrentId(), .Unordered); + } // Return error.Timeout if we know the timeout elapsed correctly. if (rc == os.windows.FALSE) { |
