Single-threaded context for rust

A while ago I came up with the idea of a single threaded context for the rust language. I imagine that this could be a compiler feature, so you could add single-threaded-modules to your rust project which may only run on a single thread. In a single-threaded context you could probably remove the whole mut / immutable principals from the rust language. I thought that this could probably simplify a lot of things writing more complex programs in rust, f.e.: single threaded web server nodes, like node js but with the benefit of the performance of a non garbage collected language. Let me know if this could work, which other benefits this could have and what would be not so good about this!

You can already do this by using non-Send types. For example, actix-web does this by spawning several isolated single-threaded runtimes that don't really communicate with each other.

It's not that simple. See e.g. the following articles:

  1. The Problem With Single-threaded Shared Mutability
  2. Temporarily opt-in to shared mutation

These articles discuss various aspects of single-threaded shared mutability.


Thank you for your quick response, I will look into it

Not really, because problems like iterator invalidation and function re-entrancy exist even in single threaded programs.


In my experience pretty much every single threaded program becomes multi-threaded at some point.

It would be terrible to find one had thousands of lines of code with the mut/immut thing turned off that could then not be easily threaded.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.