diff --git a/std/mutex.zig b/std/mutex.zig index 125a76347..c0b5d3b00 100644 --- a/std/mutex.zig +++ b/std/mutex.zig @@ -96,7 +96,7 @@ const MutexWindows = struct { pub fn acquire(self: *Mutex) Held { self.initOsData(); - windows.EnterCriticalSection(&self.lock); + while (windows.TryEnterCriticalSection(&self.lock) == 0) {} return Held { .mutex = self }; } }; diff --git a/std/os/windows/kernel32.zig b/std/os/windows/kernel32.zig index 1691b6523..141039a15 100644 --- a/std/os/windows/kernel32.zig +++ b/std/os/windows/kernel32.zig @@ -222,7 +222,7 @@ pub const FOREGROUND_RED = 4; pub const FOREGROUND_INTENSITY = 8; pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; -pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; +pub extern "kernel32" stdcallcc fn TryEnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) BOOL; pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;