| author | |
| committer | |
| log | fd65cdc55a21640cf67a4a1b6ff8b58ad8c390fd |
| tree | a11207e17878cf28be03a1076bdfe14603407e7a |
| parent | c47c2a2f2a518c8878a081dd30a631f5bc21eefa |
| signature |
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.2 files changed, 8 insertions(+), 2 deletions(-)
std/os.zig+5-1| ... | ... | @@ -2959,6 +2959,10 @@ pub const Thread = struct { |
| 2959 | 2959 | |
| 2960 | 2960 | /// Returns the handle of this thread. |
| 2961 | 2961 | /// On Linux and POSIX, this is the same as Id. |
| 2962 | /// On Linux, it is possible that the thread spawned with `spawnThread` | |
| 2963 | /// finishes executing entirely before the clone syscall completes. In this | |
| 2964 | /// case, this function will return 0 rather than the no-longer-existing thread's | |
| 2965 | /// pid. | |
| 2962 | 2966 | pub fn handle(self: Thread) Handle { |
| 2963 | 2967 | return self.data.handle; |
| 2964 | 2968 | } |
| ... | ... | @@ -2977,7 +2981,7 @@ pub const Thread = struct { |
| 2977 | 2981 | } else switch (builtin.os) { |
| 2978 | 2982 | builtin.Os.linux => { |
| 2979 | 2983 | while (true) { |
| 2980 | const pid_value = @atomicLoad(i32, &self.data.handle, builtin.AtomicOrder.SeqCst); | |
| 2984 | const pid_value = @atomicLoad(i32, &self.data.handle, .SeqCst); | |
| 2981 | 2985 | if (pid_value == 0) break; |
| 2982 | 2986 | const rc = linux.futex_wait(&self.data.handle, linux.FUTEX_WAIT, pid_value, null); |
| 2983 | 2987 | switch (linux.getErrno(rc)) { |
std/os/test.zig+3-1| ... | ... | @@ -49,7 +49,9 @@ test "std.os.Thread.getCurrentId" { |
| 49 | 49 | switch (builtin.os) { |
| 50 | 50 | builtin.Os.windows => expect(os.Thread.getCurrentId() != thread_current_id), |
| 51 | 51 | else => { |
| 52 | expect(thread_current_id == thread_id); | |
| 52 | // If the thread completes very quickly, then thread_id can be 0. See the | |
| 53 | // documentation comments for `std.os.Thread.handle`. | |
| 54 | expect(thread_id == 0 or thread_current_id == thread_id); | |
| 53 | 55 | }, |
| 54 | 56 | } |
| 55 | 57 | } |