authorgravatar for alex.franchuk@gmail.comafranchuk <alex.franchuk@gmail.com> 2022-01-11 13:04:24-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-12 11:59:09-07:00
log511990c83ba7f27ddf62a2067fa9d773aff26aa2
tree517087a7b15f203bff764a2f1875ecb82046ed89
parent9fa55ae77745da919cf14ee771dd5ee02f667205

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.

2 files changed, 26 insertions(+), 2 deletions(-)

lib/std/Thread.zig+24
......@@ -1151,3 +1151,27 @@ test "Thread.detach" {
11511151 event.wait();
11521152 try std.testing.expectEqual(value, 1);
11531153}
1154
1155fn testWaitForSignal(mutex: *Mutex, cond: *Condition) void {
1156 mutex.lock();
1157 defer mutex.unlock();
1158 cond.signal();
1159 cond.wait(mutex);
1160}
1161
1162test "Condition.signal" {
1163 if (builtin.single_threaded) return error.SkipZigTest;
1164
1165 var mutex = Mutex{};
1166 var cond = Condition{};
1167
1168 var thread: Thread = undefined;
1169 {
1170 mutex.lock();
1171 defer mutex.unlock();
1172 thread = try Thread.spawn(.{}, testWaitForSignal, .{ &mutex, &cond });
1173 cond.wait(&mutex);
1174 cond.signal();
1175 }
1176 thread.join();
1177}
lib/std/Thread/Condition.zig+2-2
......@@ -106,7 +106,7 @@ pub const AtomicCondition = struct {
106106 .linux => {
107107 switch (linux.getErrno(linux.futex_wait(
108108 &cond.futex,
109 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,
109 linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
110110 0,
111111 null,
112112 ))) {
......@@ -128,7 +128,7 @@ pub const AtomicCondition = struct {
128128 .linux => {
129129 switch (linux.getErrno(linux.futex_wake(
130130 &cond.futex,
131 linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
131 linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
132132 1,
133133 ))) {
134134 .SUCCESS => {},