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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ pub const AtomicCondition = struct {
|
||||
.linux => {
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
&cond.futex,
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
|
||||
0,
|
||||
null,
|
||||
))) {
|
||||
@@ -128,7 +128,7 @@ pub const AtomicCondition = struct {
|
||||
.linux => {
|
||||
switch (linux.getErrno(linux.futex_wake(
|
||||
&cond.futex,
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
|
||||
1,
|
||||
))) {
|
||||
.SUCCESS => {},
|
||||
|
||||
Reference in New Issue
Block a user