summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Osborne <osbpau@gmail.com>2016-10-27 22:27:14 -0400
committerPaul Osborne <osbpau@gmail.com>2016-10-27 22:27:14 -0400
commitaea291ed2b4b0ecc34ffb817ce31f0583d6a3c70 (patch)
tree83e0b20790c84943a1c99c9e6aafef8a39051852
parenta2e0c057bd9acd60b687ed8a2817d69be104d599 (diff)
downloadnix-aea291ed2b4b0ecc34ffb817ce31f0583d6a3c70.zip
unistd: add documentation for gettid
Signed-off-by: Paul Osborne <osbpau@gmail.com>
-rw-r--r--src/unistd.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index 36f72c31..dce3a39a 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -124,10 +124,20 @@ pub fn setsid() -> Result<pid_t> {
Errno::result(unsafe { libc::setsid() })
}
+/// Get the caller's thread ID (see
+/// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html).
+///
+/// This function is only available on Linux based systems. In a single
+/// threaded process, the main thread will have the same ID as the process. In
+/// a multithreaded process, each thread will have a unique thread id but the
+/// same process ID.
+///
+/// No error handling is required as a thread id should always exist for any
+/// process, even if threads are not being used.
#[cfg(any(target_os = "linux", target_os = "android"))]
#[inline]
pub fn gettid() -> pid_t {
- unsafe { libc::syscall(libc::SYS_gettid) as pid_t } // no error handling, according to man page: "These functions are always successful."
+ unsafe { libc::syscall(libc::SYS_gettid) as pid_t }
}
#[inline]