authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-06 17:30:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-06 17:31:52-04:00
log24d74cbf44b34b180b2df5557927d9d2e4c9e443
treed63d84c3eba4cd1d9c28a41ac7979eeff4784843
parentd2dd29e80c89d8cc530a185e32e9025d0e453bb5

fix Thread impl on Linux and add docs


2 files changed, 5 insertions(+), 2 deletions(-)

std/os/index.zig+4-1
......@@ -2519,6 +2519,7 @@ pub const Thread = struct {
25192519
25202520 /// Represents a kernel thread handle.
25212521 /// May be an integer or a pointer depending on the platform.
2522 /// On Linux and POSIX, this is the same as Id.
25222523 pub const Handle = if (use_pthreads)
25232524 c.pthread_t
25242525 else switch (builtin.os) {
......@@ -2557,6 +2558,7 @@ pub const Thread = struct {
25572558
25582559 /// Returns the ID of the calling thread.
25592560 /// Makes a syscall every time the function is called.
2561 /// On Linux and POSIX, this Id is the same as a Handle.
25602562 pub fn getCurrentId() Id {
25612563 if (use_pthreads) {
25622564 return c.pthread_self();
......@@ -2569,7 +2571,8 @@ pub const Thread = struct {
25692571 }
25702572
25712573 /// Returns the handle of this thread.
2572 pub fn handle(self: Thread) Thread.Handle {
2574 /// On Linux and POSIX, this is the same as Id.
2575 pub fn handle(self: Thread) Handle {
25732576 return self.data.handle;
25742577 }
25752578
std/os/test.zig+1-1
......@@ -41,11 +41,11 @@ fn testThreadIdFn(thread_id: *os.Thread.Id) void {
4141test "std.os.Thread.getCurrentId" {
4242 var thread_current_id: os.Thread.Id = undefined;
4343 const thread = try os.spawnThread(&thread_current_id, testThreadIdFn);
44 const thread_id = thread.handle();
4445 thread.wait();
4546 switch (builtin.os) {
4647 builtin.Os.windows => assert(os.Thread.getCurrentId() != thread_current_id),
4748 else => {
48 const thread_id = thread.handle();
4949 assert(thread_current_id == thread_id);
5050 },
5151 }