Commit 24d74cbf44

Andrew Kelley <superjoe30@gmail.com>
2018-08-06 23:30:55
fix Thread impl on Linux and add docs
1 parent d2dd29e
Changed files (2)
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;
     }
 
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);
         },
     }