-
Notifications
You must be signed in to change notification settings - Fork 560
Tighten Send and Sync requirements #443
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
Conversation
rayon-core/src/scope/mod.rs
Outdated
| // the `Scope` is not send or sync, and we only give out | ||
| // pointers to it from within a worker thread | ||
| debug_assert!(!WorkerThread::current().is_null()); | ||
| debug_assert!(!worker_thread.is_null()); |
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.
Note, Scope now does implement Sync, so this comment isn't true anymore. We need to evaluate whether that's actually safe. I think here, this !is_null() should probably be a full assert!, and perhaps we assert that the current registry matches that saved in the Scope too.
rayon-core/src/scope/mod.rs
Outdated
| debug_assert!(!worker_thread.is_null()); | ||
|
|
||
| let worker_thread = &*worker_thread; | ||
| worker_thread.push(job_ref); |
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.
Maybe this can just switch to scope.registry.inject_or_push(job_ref), so if the scope does get carried out of the threadpool, it still spawns back to the right pool. The 'scope lifetime should still ensure the right stuff...
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.
Done.
|
|
||
| let worker_thread = &*worker_thread; | ||
| worker_thread.push(job_ref); | ||
| self.registry.inject_or_push(job_ref); |
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.
Let's add a comment here saying that it would be unsafe to just invoke push before we don't know that the scope was not somehow sent to another thread.
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.
Done.
nikomatsakis
left a comment
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.
Left a nit with a minor documentation change, but otherwise looks good.
This is a **breaking change** to `rayon-core`, necessary for soundness. - `Scope::spawn` now requires `Send` for the closure. Fixes rayon-rs#430. - `ThreadPool::install` now requires `Send` for the return value. - (unstable) `internal::Task` now requires `Send + Sync` instead of just `Send`, so its use of `Arc` properly implements `Send` and `Sync` too.
This adds `Registry::in_worker()`, akin to the free `fn in_worker()` but for a particular thread pool. If this is called from a thread that's part of that pool, it just executes the `op` directly. `ThreadPool::install()` now simply forwards to `Registry::in_worker()`. Fixes rayon-rs#446.
|
Added a fix for #446, since that also needed the change to |
This is a breaking change to
rayon-core, necessary for soundness.Scope::spawnnow requiresSendfor the closure. Fixes Scope::spawn doesn't requireSend#430.ThreadPool::installnow requiresSendfor the return value.(unstable)
internal::Tasknow requiresSend + Syncinstead of justSend, so its use ofArcproperly implementsSendandSynctoo.