Using Mun in a threaded environment #299
Labels
pri: intermediate
An issue resulting in non-critical functionality loss and no significant effect on usability
type: feat
New feature or request
Milestone
The
mun_runtime::Runtime
is notSync
norSend
since theRuntimeBuilder::spawn
function returns aRc<RefCell<Runtime>>
. This makes it hard to use in other programs that make use of threads. The reason we wrap theRuntime
in anRc
is because the runtime (or better yet, the memory model) is not thread safe. Wrapping theRuntime
in a mutex will also not work because the memory model is shared between other structs (likeStructRef
). Sending theRuntime
to a thread and doing modifications while also accessing aStructRef
from another thread will cause threading issues.We've already talked about this a lot. We currently have no proper plan to support multithreading. However, our current solution is also not very ergonomic. I propose we implement a blocking solution that still doesnt do multithreading of the runtime but does allow the runtime and derived data to be shared across threads. In a later version we can then add proper multithreading hopefully using the same API we design now.
A straighforward solution is to wrap all memory modifying operations inside a mutex. This will block any operation performed by other threads but will enable the use of the Runtime and derived data to be send to different threads.
Curious to your thoughts!
The text was updated successfully, but these errors were encountered: