3 ms·
If a thread is waiting for I/O or a mutex, it will yield and let another thread use that CPU time to do something. This doesn't work if you don't have more thre
by marginalia_nu 5y ago
If a thread is waiting for I/O or a mutex, it will yield and let another thread use that CPU time to do something. This doesn't work if you don't have more threads than logical cores, because then there is no job that can take over.
We've had this type of cpu time sharing far longer than we've had multicore CPUs.
- tcfhgj 5y agoDoes this still hold if you use async/await which simply would push a different task on the thread while the other one is waiting?
- marginalia_nu 5y agoAs far as the operating system is concerned, a thread is a thread. Async/await is a pattern for hiding the implementation details of multitasking or faking it in languages with limited support, it still largely works the same, except you see it as the thread being yielded to rather than from in explicit threading.
- zozbot234 5y agoAsync-await uses non-blocking operations in the kernel. If blocking operations need to occur, then these can occur on a separate thread but this is rare. Most things have a non-blocking equivalent.
- preseinger 5y agoAsync/await is an abstraction that exists at a layer above OS threads. "Non-blocking" isn't well defined when speaking about OS threading models.