4 ms·
There are many systems that I've worked on that do this in practice. So firstly, a common use-case of threads is for improving performance. Using a job system
by Arelius 7y ago
There are many systems that I've worked on that do this in practice.
So firstly, a common use-case of threads is for improving performance. Using a job system is a good mechanism for this that doesn't strongly couple the architecture to the details of number of threads, or etc. Often this can be done with a fork-join model, where when you have a big chunk of work to do, you can create a bunch of jobs to do some work, then either wait on them immediately, or go off and do some other work while you wait, either approach works since it's possible to have a job system that will do work on the waiting thread.
At this point it's then pretty simple to either build in a fallback either directly into the job system, where you either do the work immediately upon launching it, or upon waiting on it. or it's trivial to detect presence of threads in the work code, and replace the job code with a simple for loop or something similar.
This is far from the only style of system I've seen that can work optionally with threads, but it's one I've seen working to good effect.