From 5b668dba2b627357164b7e0e6fa1d9de61513fc6 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 23 Mar 2022 19:48:13 +0200 Subject: [PATCH] sync: document sync.thread_id() --- vlib/sync/thread_default.c.v | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vlib/sync/thread_default.c.v b/vlib/sync/thread_default.c.v index 74d6d517c..81bcf105e 100644 --- a/vlib/sync/thread_default.c.v +++ b/vlib/sync/thread_default.c.v @@ -2,6 +2,14 @@ module sync fn C.pthread_self() usize +// thread_id returns a unique identifier for the caller thread. +// All *currently* running threads in the same process, will have *different* thread identifiers. +// Note: if a thread finishes, and another starts, the identifier of the old thread may be +// reused for the newly started thread. +// In other words, thread IDs are guaranteed to be unique only within a process. +// A thread ID may be reused after a terminated thread has been joined (with `t.wait()`), +// or when the thread has terminated. + pub fn thread_id() u64 { return u64(C.pthread_self()) } -- 2.30.2