aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-06 17:30:55 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-08-06 17:31:52 -0400
commit24d74cbf44b34b180b2df5557927d9d2e4c9e443 (patch)
treed63d84c3eba4cd1d9c28a41ac7979eeff4784843 /std
parentd2dd29e80c89d8cc530a185e32e9025d0e453bb5 (diff)
downloadzig-24d74cbf44b34b180b2df5557927d9d2e4c9e443.tar.gz
zig-24d74cbf44b34b180b2df5557927d9d2e4c9e443.zip
fix Thread impl on Linux and add docs
Diffstat (limited to 'std')
-rw-r--r--std/os/index.zig5
-rw-r--r--std/os/test.zig2
2 files changed, 5 insertions, 2 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index 6f124df4ed..d47444d67d 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -2519,6 +2519,7 @@ pub const Thread = struct {
/// Represents a kernel thread handle.
/// May be an integer or a pointer depending on the platform.
+ /// On Linux and POSIX, this is the same as Id.
pub const Handle = if (use_pthreads)
c.pthread_t
else switch (builtin.os) {
@@ -2557,6 +2558,7 @@ pub const Thread = struct {
/// Returns the ID of the calling thread.
/// Makes a syscall every time the function is called.
+ /// On Linux and POSIX, this Id is the same as a Handle.
pub fn getCurrentId() Id {
if (use_pthreads) {
return c.pthread_self();
@@ -2569,7 +2571,8 @@ pub const Thread = struct {
}
/// Returns the handle of this thread.
- pub fn handle(self: Thread) Thread.Handle {
+ /// On Linux and POSIX, this is the same as Id.
+ pub fn handle(self: Thread) Handle {
return self.data.handle;
}
diff --git a/std/os/test.zig b/std/os/test.zig
index ee5f253f7b..82054d3f32 100644
--- a/std/os/test.zig
+++ b/std/os/test.zig
@@ -41,11 +41,11 @@ fn testThreadIdFn(thread_id: *os.Thread.Id) void {
test "std.os.Thread.getCurrentId" {
var thread_current_id: os.Thread.Id = undefined;
const thread = try os.spawnThread(&thread_current_id, testThreadIdFn);
+ const thread_id = thread.handle();
thread.wait();
switch (builtin.os) {
builtin.Os.windows => assert(os.Thread.getCurrentId() != thread_current_id),
else => {
- const thread_id = thread.handle();
assert(thread_current_id == thread_id);
},
}