Skip to content

Conversation

@cuviper
Copy link
Member

@cuviper cuviper commented Sep 19, 2017

This is a breaking change to rayon-core, necessary for soundness.

  • Scope::spawn now requires Send for the closure. Fixes Scope::spawn doesn't require Send #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.

// 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());
Copy link
Member Author

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.

debug_assert!(!worker_thread.is_null());

let worker_thread = &*worker_thread;
worker_thread.push(job_ref);
Copy link
Member Author

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...

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@nikomatsakis nikomatsakis left a 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.
@cuviper
Copy link
Member Author

cuviper commented Sep 23, 2017

Added a fix for #446, since that also needed the change to install() here.

@nikomatsakis nikomatsakis merged commit 3217551 into rayon-rs:master Sep 25, 2017
@cuviper cuviper deleted the job-sync branch October 6, 2017 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants