diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-04-05 16:04:27 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-04-05 16:06:35 -0400 |
| commit | fd65cdc55a21640cf67a4a1b6ff8b58ad8c390fd (patch) | |
| tree | a11207e17878cf28be03a1076bdfe14603407e7a /std/os.zig | |
| parent | c47c2a2f2a518c8878a081dd30a631f5bc21eefa (diff) | |
| download | zig-fd65cdc55a21640cf67a4a1b6ff8b58ad8c390fd.tar.gz zig-fd65cdc55a21640cf67a4a1b6ff8b58ad8c390fd.zip | |
fix incorrect Thread.getCurrentId test
Documentation comments copied here:
On Linux, it is possible that the thread spawned with `spawnThread`
finishes executing entirely before the clone syscall completes. In this
case, `std.os.Thread.handle` will return 0 rather than the
no-longer-existing thread's pid.
Diffstat (limited to 'std/os.zig')
| -rw-r--r-- | std/os.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/std/os.zig b/std/os.zig index b89b2a9ce2..d641cf29c9 100644 --- a/std/os.zig +++ b/std/os.zig @@ -2959,6 +2959,10 @@ pub const Thread = struct { /// Returns the handle of this thread. /// On Linux and POSIX, this is the same as Id. + /// On Linux, it is possible that the thread spawned with `spawnThread` + /// finishes executing entirely before the clone syscall completes. In this + /// case, this function will return 0 rather than the no-longer-existing thread's + /// pid. pub fn handle(self: Thread) Handle { return self.data.handle; } @@ -2977,7 +2981,7 @@ pub const Thread = struct { } else switch (builtin.os) { builtin.Os.linux => { while (true) { - const pid_value = @atomicLoad(i32, &self.data.handle, builtin.AtomicOrder.SeqCst); + const pid_value = @atomicLoad(i32, &self.data.handle, .SeqCst); if (pid_value == 0) break; const rc = linux.futex_wait(&self.data.handle, linux.FUTEX_WAIT, pid_value, null); switch (linux.getErrno(rc)) { |
