aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread.zig
diff options
context:
space:
mode:
authorafranchuk <alex.franchuk@gmail.com>2022-01-11 13:04:24 -0500
committerGitHub <noreply@github.com>2022-01-11 13:04:24 -0500
commit7c4c49ff07de31b1b74f3dc26648ad4000113256 (patch)
tree3c341e33f24af527ee93d14b829befa20c421bb3 /lib/std/Thread.zig
parent64363b10f5fad74c8c6ca279bba632b6dde8482f (diff)
downloadzig-7c4c49ff07de31b1b74f3dc26648ad4000113256.tar.gz
zig-7c4c49ff07de31b1b74f3dc26648ad4000113256.zip
Fix a bug in std.Thread.Condition and add a basic Condition test. (#10538)
* Fix FUTEX usage in std.Thread.Condition - It was using an old name.
Diffstat (limited to 'lib/std/Thread.zig')
-rw-r--r--lib/std/Thread.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index f2203e2808..83c2992a45 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -1151,3 +1151,27 @@ test "Thread.detach" {
event.wait();
try std.testing.expectEqual(value, 1);
}
+
+fn testWaitForSignal(mutex: *Mutex, cond: *Condition) void {
+ mutex.lock();
+ defer mutex.unlock();
+ cond.signal();
+ cond.wait(mutex);
+}
+
+test "Condition.signal" {
+ if (builtin.single_threaded) return error.SkipZigTest;
+
+ var mutex = Mutex{};
+ var cond = Condition{};
+
+ var thread: Thread = undefined;
+ {
+ mutex.lock();
+ defer mutex.unlock();
+ thread = try Thread.spawn(.{}, testWaitForSignal, .{ &mutex, &cond });
+ cond.wait(&mutex);
+ cond.signal();
+ }
+ thread.join();
+}