-
Notifications
You must be signed in to change notification settings - Fork 506
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
spawn
is badly named
#743
Comments
I'm sorry for the confusion!
Yes -- For comparison, the If we do change, we don't want to break the 1.x API with a rename/removal, so we could only deprecate the In general, blocking a rayon job on the result from another rayon job is a dangerous thing to do. It's fine if that blocking is controlled by the pool itself, like a |
Just a remark from multithreading in other languages: The What you are looking for is a threadpool for blocking tasks while Rayon is a scheduler for compute tasks. The difference between a blocking task and a compute task is that a compute task must be actively scheduled to make progress, unlike reading for stdin for example. I.e.
Regarding your bug per se, this should be solved by Rayon futures (i.e. Rayon supporting sync from the spawn/sync Cilk/Task parallelism paradigm) |
@mratsim Yes I understand the difference. But I think it is much clearer to talk about scheduling a task, and spawning a thread. That is the common lingo in my experience, in spite of the languages/libraries you listed naming things weirdly. Here are some examples of people talking about spawning threads: A, B, C. Here are some examples of thread pool Rust itself seems to have got it right: |
Cilk was created in 1995 and is the foundational research behind work-stealing schedulers: They use spawn/sync for tasks: http://supertech.csail.mit.edu/papers/PPoPP95.pdf pthread C11 and C++11 use create/join: https://en.cppreference.com/w/cpp/thread/thread In my opinion, Rust standard library made a mistake in using The new Executor draft for C++ also use spawn for executors: |
Would it be possible to add a method to Rayon that actually does spawn a new thread and not use a threadpool? I realise in most cases this would be equivalent to |
@RReverser I don't think there's a way for us to keep the |
@cuviper Hmm, yeah, I see. I suspect most custom |
Well, the provided *(rustc really uses a rustc-rayon fork, not rayon directly) |
I wonder if there's a generic param we could add to |
Is there a reason you can't or don't want to store an independent thread spawner for your case? It seems out of scope to me to have |
The reason is that, on the library side, I'm not in control of the thread spawner, I'm only using rayon APIs and leaving it up to the actual app to decide whether it wants to use a regular pool, or to I guess it would be possible to add spawn handler as an option of the library itself, but then it's the user who needs to pass it to several different places rather than preconfigure just once, and seems like a poor DX. |
Just ran into an issue related to misleading |
We just had a difficult to diagnose deadlock bug essentially because
spawn()
is badly named. The situation was something like this:Normally this worked fine! But on some systems it seemed to get stuck. We eventually figured out that
spawn()
, despite its name does not actually spawn a thread. It schedules a task! On systems where the thread pool had 2 or more threads, bothr.recv()
anddo_some_slow_work()
could progress, but when we happened to run on a system where the thread pool only had one thread we could sometimes get tor.recv()
and block forever sodo_some_slow_work()
never had a chance to run.What's the solution? Don't use
spawn()
because it doesn't spawn a thread. Instead usespawn()
which does spawn a thread! Pretty confusing naming right?Here is the patch to fix the bug we had - hopefully you can why this was confusing!
I suggest something like
execute()
,schedule()
,queue()
,add_task()
, etc.The text was updated successfully, but these errors were encountered: