Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC proposal for thread affinity #1480
Conversation
jamperry
added some commits
Jan 26, 2016
alexcrichton
added
the
T-libs
label
Jan 26, 2016
durka
reviewed
Jan 28, 2016
| // locks thread to cpu core 2 | ||
| let t = thread::spawn(move || { | ||
| let cpu_no = 2; | ||
| let cpu_lock = CpuLock::lock_on(cpu_no).unwrap(); // the current thread is now locked to an arbitrary free CPU core |
This comment has been minimized.
This comment has been minimized.
durka
reviewed
Jan 28, 2016
| // locks thread to cpu core 2 | ||
| let cpu_no = 2; | ||
| let t = thread::lock_on(2,move || { | ||
| let cpu_lock = CpuLock::lock_on(cpu_no).unwrap(); // the current thread is now locked to an arbitrary free CPU core |
This comment has been minimized.
This comment has been minimized.
durka
Jan 28, 2016
Contributor
if lock_on is analogous to lock, this line and the one after it shouldn't be here
retep998
reviewed
Feb 2, 2016
| # Alternatives | ||
| [alternatives]: #alternatives | ||
|
|
||
| Calling unsafe OS-specific system calls to create threads and changing the affinity mask because `std::thread::Thread` do not expose the underling OS-specific thread id (AFIAW). |
This comment has been minimized.
This comment has been minimized.
retep998
Feb 2, 2016
Member
JoinHandle is what actually contains the OS-specific thread handle. On Windows JoinHandle implements AsRawHandle and IntoRawHandle and on non-windows it implements JoinHandleExt. Also getting the handle to the current thread is pretty simple (GetCurrentThread or pthread_self depending on your platform).
retep998
reviewed
Feb 2, 2016
|
|
||
| I split it into two parts: *User API* and *Implementation*. | ||
|
|
||
| ### Locking to an arbitrary free CPU core |
This comment has been minimized.
This comment has been minimized.
retep998
Feb 2, 2016
Member
There's a lot of room for detail on how exactly it locks to an arbitrary free CPU core. Does it determine what CPU core the thread is currently executing on and then lock to that? Does it pick a random CPU core?
This comment has been minimized.
This comment has been minimized.
|
Relevant discussion on Rust internals https://internals.rust-lang.org/t/pre-rfc-thread-affinity/3117/9 |
retep998
reviewed
Feb 2, 2016
|
|
||
| * Is it possible for consistent & symmetric semantics across all supported operating systems? | ||
|
|
||
| * Is it better to be an external library rather than in std? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
peterhj
commented
Feb 5, 2016
|
Thread affinity is something I'm sorely needing in Rust today as well. Some immediate comments on the RFC:
There are also general comments which I think concern the affinity implementations for any language's standard library. Dumping some here off the top of my head:
It could be interesting if libstd received a standard way of querying CPU topology. But more likely it'll start off as just another library, which is just fine if it just works. |
alexcrichton
self-assigned this
Mar 2, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the RFC @jamperry! The discussion here and on the internals forum leads me to think that this may best be served by starting as an external library? It sounds like there's a lot of competing possible strategies and there's a lot of concerns to take into account. Taking some time to flesh out the library externally, get some experience, and toy with an API may be the best step forward here? |
alexcrichton
added
the
I-nominated
label
Mar 30, 2016
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Apr 15, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
I agree with @retep998, @alexcrichton and others that this work should start in an external library and be considered for addition to |
This comment has been minimized.
This comment has been minimized.
diwic
commented
Apr 25, 2016
|
If implemented, how about using the thread Builder like this: |
This comment has been minimized.
This comment has been minimized.
Florob
commented
May 2, 2016
|
Like others I think this should (at least initially) live in an external library. |
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this RFC at triage today and the decision was to close for now. There doesn't appear to be a fundamental reason why this needs to be in the standard library right now, and otherwise it seems like this can be developed externally on crates.io Thanks again though for the RFC @jamperry! |
jamperry commentedJan 26, 2016
No description provided.