-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add methods to get the ID of a std.os.Thread, and to get ID of current thread #1316
Comments
On a second look, I think I can try to put together a PR for this after all. (Also, the code above doesn't compile, so that needs some work...) |
I think you can accomplish this in the places you need it (e.g. in your allocator code) with thread local storage (#924) like this: var next_global_id: usize = 1;
threadlocal var thread_id: usize = 0;
fn getThreadId() usize {
const id = thread_id;
if (id != 0) return id;
const allocated_id = @atomicRmw(usize, &next_global_id, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
thread_id = allocated_id;
return allocated_id;
} Every thread gets assigned a unique id, which you could use in your mutex or allocator use cases to distinguish. This
|
Being able to get the current thread ID would be handy for various things. Here are two specific examples that are relevant to the project I'm working on at the moment:
Strawman proposal for code in
std/os/index.zig
:The text was updated successfully, but these errors were encountered: