3 ms·
Not the person you were asking the question to, but I can give you tons of examples. This is particularly true in the embedded space or people who write C or C+
by sgerenser 7y ago
Not the person you were asking the question to, but I can give you tons of examples. This is particularly true in the embedded space or people who write C or C++ that doesn’t have any standard event library. Basically, threads are a lowest-common denominator way to do blocking operations without stalling everything. I’ve seen a lot of code where there’s various threads running at different intervals (low priority background thread that sleeps for 1 second then wakes up to do stuff, another thread that does nothing but blink an LED, etc.) But in reality, in most non-cpu bound workloads, using an event loop would make writing this kind of code much easier and you woulnd’t ever have to worry about mutexes, semaphores, deadlocks, etc. As a C++ programmer, using Qt (even for non-UI stuff) with its event loop is just so much easier than spinning up threads just to call a network endpoint.
That being said, threads definitely have their place and are the only real way to take advantage of all the power offered by modern multi-core CPUs (well that and multi-process but that’s not really any easier to get right). But for the basic stuff I think running 80 threads when your app is only using 5% cpu is insane (something I see a lot in the C++ code I’m exposed to).
- chrisseaton 7y agoAren't all your examples still examples of concurrency? > way to do blocking operations without stalling everything Switching between multiple tasks doing IO - that's concurrency isn't it? > various threads running at different intervals (low priority background thread that sleeps for 1 second then wakes up to do stuff Different tasks ready to run and switching between them as needed - that's concurrency again isn't it? Not really sure what everyone else in this thread is seeing that I'm not.
- justincredible 7y agoThe confusion might be due to everyone using concurrency to mean concurrency and/or parallelism.
- sgerenser 7y agoOK, sure those are actually examples of concurrency. I was thinking of concurrency more along the lines of multiple threads of execution doing useful work at the same time, which threads are actually good at doing but these examples are not that.