Right now the multithreading is not safe or efficient. We run each module on a separate thread without any synchronization. The physics module runs on a single thread, saturating that thread, while the rest of the threads barely do any work. Additionally, there are problems with the modifying state across multiple threads without synchronization, producing this bug (#146). Secondly, there exist problem areas where the performance suffers substantially because the ownership of certain tasks is ambiguous or incorrectly placed (#141).
To solve this, we could use a task-based approach so that the workloads get distributed across all threads. This also helps to ensure thread safety because each task can be arranged to avoid conflicts. This has become a standard in real-time applications to do it this way.
We could look into using a higher-level threading library that supports tasks such as this: https://www.threadingbuildingblocks.org/