4 ms·
Do you have a real system that uses threads if available, but can also work without them? What does the architecture look like?
by tlb 7y ago
Do you have a real system that uses threads if available, but can also work without them? What does the architecture look like?
- Hello71 7y agothere are other threading options available than C11.
- toast0 7y agoBEAM, the Erlang virtual machine, could be compiled with or without threads until release 21 (from 2018).
- com2kid 7y agoPlenty of embedded libraries of optional thread support, though from what I've seen this option is explicitly enabled by setting a define specific to that library, and also passing in other needed info/function pointers since threading can vary so much on embedded systems.
- Arelius 7y agoThere 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.