-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 a numeric ID to threads #29448
Add a numeric ID to threads #29448
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ unsafe impl Send for Thread {} | |
unsafe impl Sync for Thread {} | ||
|
||
impl Thread { | ||
pub unsafe fn new<'a>(stack: usize, p: Box<FnBox() + 'a>) | ||
pub unsafe fn new<'a>(stack: usize, p: Box<FnBox(u32) + 'a>) | ||
-> io::Result<Thread> { | ||
let p = box p; | ||
let mut native: libc::pthread_t = mem::zeroed(); | ||
|
@@ -71,7 +71,7 @@ impl Thread { | |
}; | ||
|
||
extern fn thread_start(main: *mut libc::c_void) -> *mut libc::c_void { | ||
unsafe { start_thread(main); } | ||
unsafe { start_thread(main, pthread_self() as u32); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So should we use a typedef around what a thread ID is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Linux pthread_t is I'm starting to think that using the address of the Inner struct is way simpler and would totally work (it's what I used for #29447) if we want "some kind of ID" and don't care for the OS-provided ID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Windows what I want is some sort of OS provided ID. Either the thread There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, I'm fine with this just providing some sort of unique numerical ID that has no meaning other than to distinguish threads. I'll work on a PR to add OS specific APIs for getting the |
||
ptr::null_mut() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why’d you want to pass the thread id as an argument into the thread instead of e.g. providing a static method on
Thread
which callspthread_self
.