diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/Thread/Condition.zig | 23 | ||||
| -rw-r--r-- | lib/std/fs/test.zig | 15 | ||||
| -rw-r--r-- | lib/std/os/linux.zig | 4 |
3 files changed, 37 insertions, 5 deletions
diff --git a/lib/std/Thread/Condition.zig b/lib/std/Thread/Condition.zig index 09911df883..bc579878da 100644 --- a/lib/std/Thread/Condition.zig +++ b/lib/std/Thread/Condition.zig @@ -330,10 +330,12 @@ test "Condition - wait and signal" { mutex: Mutex = .{}, cond: Condition = .{}, threads: [num_threads]std.Thread = undefined, + spawn_count: std.math.IntFittingRange(0, num_threads) = 0, fn run(self: *@This()) void { self.mutex.lock(); defer self.mutex.unlock(); + self.spawn_count += 1; self.cond.wait(&self.mutex); self.cond.timedWait(&self.mutex, std.time.ns_per_ms) catch {}; @@ -346,7 +348,14 @@ test "Condition - wait and signal" { t.* = try std.Thread.spawn(.{}, MultiWait.run, .{&multi_wait}); } - std.time.sleep(100 * std.time.ns_per_ms); + while (true) { + std.time.sleep(100 * std.time.ns_per_ms); + + multi_wait.mutex.lock(); + defer multi_wait.mutex.unlock(); + // Make sure all of the threads have finished spawning to avoid a deadlock. + if (multi_wait.spawn_count == num_threads) break; + } multi_wait.cond.signal(); for (multi_wait.threads) |t| { @@ -367,10 +376,12 @@ test "Condition - signal" { cond: Condition = .{}, notified: bool = false, threads: [num_threads]std.Thread = undefined, + spawn_count: std.math.IntFittingRange(0, num_threads) = 0, fn run(self: *@This()) void { self.mutex.lock(); defer self.mutex.unlock(); + self.spawn_count += 1; // Use timedWait() a few times before using wait() // to test multiple threads timing out frequently. @@ -394,10 +405,16 @@ test "Condition - signal" { t.* = try std.Thread.spawn(.{}, SignalTest.run, .{&signal_test}); } - { - // Wait for a bit in hopes that the spawned threads start queuing up on the condvar + while (true) { std.time.sleep(10 * std.time.ns_per_ms); + signal_test.mutex.lock(); + defer signal_test.mutex.unlock(); + // Make sure at least one thread has finished spawning to avoid testing nothing. + if (signal_test.spawn_count > 0) break; + } + + { // Wake up one of them (outside the lock) after setting notified=true. defer signal_test.cond.signal(); diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index c953b529fa..15c8307f58 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1434,3 +1434,18 @@ test "delete a read-only file on windows" { file.close(); try tmp.dir.deleteFile("test_file"); } + +test "delete a setAsCwd directory on Windows" { + if (builtin.os.tag != .windows) return error.SkipZigTest; + + var tmp = tmpDir(.{}); + // Set tmp dir as current working directory. + try tmp.dir.setAsCwd(); + tmp.dir.close(); + try testing.expectError(error.FileBusy, tmp.parent_dir.deleteTree(&tmp.sub_path)); + // Now set the parent dir as the current working dir for clean up. + try tmp.parent_dir.setAsCwd(); + try tmp.parent_dir.deleteTree(&tmp.sub_path); + // Close the parent "tmp" so we don't leak the HANDLE. + tmp.parent_dir.close(); +} diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 159b0cfe56..901bb8dbb3 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -4004,7 +4004,7 @@ pub const io_uring_probe = extern struct { ops_len: u8, resv: u16, - resv2: u32[3], + resv2: [3]u32, // Followed by up to `ops_len` io_uring_probe_op structures }; @@ -4022,7 +4022,7 @@ pub const io_uring_restriction = extern struct { sqe_flags: u8, }, resv: u8, - resv2: u32[3], + resv2: [3]u32, }; /// io_uring_restriction->opcode values |
