| author | |
| committer | |
| log | 7c4c49ff07de31b1b74f3dc26648ad4000113256 |
| tree | 3c341e33f24af527ee93d14b829befa20c421bb3 |
| parent | 64363b10f5fad74c8c6ca279bba632b6dde8482f |
| signature |
* 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" { | ... | @@ -1151,3 +1151,27 @@ test "Thread.detach" { |
| 1151 | event.wait(); | 1151 | event.wait(); |
| 1152 | try std.testing.expectEqual(value, 1); | 1152 | try std.testing.expectEqual(value, 1); |
| 1153 | } | 1153 | } |
| 1154 | |||
| 1155 | fn testWaitForSignal(mutex: *Mutex, cond: *Condition) void { | ||
| 1156 | mutex.lock(); | ||
| 1157 | defer mutex.unlock(); | ||
| 1158 | cond.signal(); | ||
| 1159 | cond.wait(mutex); | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | test "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 { | ... | @@ -106,7 +106,7 @@ pub const AtomicCondition = struct { |
| 106 | .linux => { | 106 | .linux => { |
| 107 | switch (linux.getErrno(linux.futex_wait( | 107 | switch (linux.getErrno(linux.futex_wait( |
| 108 | &cond.futex, | 108 | &cond.futex, |
| 109 | linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT, | 109 | linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT, |
| 110 | 0, | 110 | 0, |
| 111 | null, | 111 | null, |
| 112 | ))) { | 112 | ))) { |
| ... | @@ -128,7 +128,7 @@ pub const AtomicCondition = struct { | ... | @@ -128,7 +128,7 @@ pub const AtomicCondition = struct { |
| 128 | .linux => { | 128 | .linux => { |
| 129 | switch (linux.getErrno(linux.futex_wake( | 129 | switch (linux.getErrno(linux.futex_wake( |
| 130 | &cond.futex, | 130 | &cond.futex, |
| 131 | linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE, | 131 | linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE, |
| 132 | 1, | 132 | 1, |
| 133 | ))) { | 133 | ))) { |
| 134 | .SUCCESS => {}, | 134 | .SUCCESS => {}, |