RFH/WIP : exec_on_worker_thread
and exec_on_main
via a threadpool
#22996
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This work is an initial attempt to implement the design in #22631 (comment)
Broadly there are two distinct functionalities -
f(args...)
on a worker thread from a threadpool. Currently libuv's threadpool is used for this, but it can be any threadpool.f(args...)
on the main thread running the event loop - required for all IO, remotecalls, etc.The Julia interface has not been added yet, you need to execute the following code block to try it out.
Julia interface:
exec_on_worker_thread(f::Function, args...)
executesf(args...)
on a thread from libuv's threadpoolexec_on_main(f::Function, args...)
is called from julia code running in a worker thread to executef(args...)
on the main thread.Examples:
foo_on_worker_thread
andbusyloop_on_worker_thread
below.Start with julia -p1 with
defined in your
.profile
or equivalent.The first example simulates a long running computation as a busyloop on a remote worker thread.
It will still be possible to execute further remotecalls on this worker (something not possible today)
The next example is one where
remotecall_fetch
, But since this involves IO and cannot be executed from the worker thread it is executed via the main thread.Note:
or
kill -9
from the shell.Status:
Need help from Julia internals gurus - review code, suggest improvements, etc.