Skip to content

Using Mun in a threaded environment #299

@baszalmstra

Description

@baszalmstra

The mun_runtime::Runtime is not Sync nor Send since the RuntimeBuilder::spawn function returns a Rc<RefCell<Runtime>>. This makes it hard to use in other programs that make use of threads. The reason we wrap the Runtime in an Rc is because the runtime (or better yet, the memory model) is not thread safe. Wrapping the Runtime in a mutex will also not work because the memory model is shared between other structs (like StructRef). Sending the Runtime to a thread and doing modifications while also accessing a StructRef 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!

Metadata

Metadata

Assignees

Labels

pri: intermediateAn issue resulting in non-critical functionality loss and no significant effect on usabilitytype: featNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions