Skip to content

Commit aea291e

Browse files
committed
unistd: add documentation for gettid
Signed-off-by: Paul Osborne <osbpau@gmail.com>
1 parent a2e0c05 commit aea291e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/unistd.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,20 @@ pub fn setsid() -> Result<pid_t> {
124124
Errno::result(unsafe { libc::setsid() })
125125
}
126126

127+
/// Get the caller's thread ID (see
128+
/// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html).
129+
///
130+
/// This function is only available on Linux based systems. In a single
131+
/// threaded process, the main thread will have the same ID as the process. In
132+
/// a multithreaded process, each thread will have a unique thread id but the
133+
/// same process ID.
134+
///
135+
/// No error handling is required as a thread id should always exist for any
136+
/// process, even if threads are not being used.
127137
#[cfg(any(target_os = "linux", target_os = "android"))]
128138
#[inline]
129139
pub fn gettid() -> pid_t {
130-
unsafe { libc::syscall(libc::SYS_gettid) as pid_t } // no error handling, according to man page: "These functions are always successful."
140+
unsafe { libc::syscall(libc::SYS_gettid) as pid_t }
131141
}
132142

133143
#[inline]

0 commit comments

Comments
 (0)