4 ms·
> threads should only be used to exercise multiple CPU cores and never as a way to work around blocking IO. Well, nothing, except the simplest of tasks, is pur
by amelius 11y ago
> threads should only be used to exercise multiple CPU cores and never as a way to work around blocking IO.
Well, nothing, except the simplest of tasks, is pure IO. If you are talking about asynchronous programming, that is basically the cooperative multitasking of the Windows 3.1 era. One event handler will, if it performs a lot of computations, block another from running. Most people seem to forget that the CPU is a resource that can be blocked too. So in the end you still end up spawning threads to reduce latency.
- jcoffland 11y agoYou may be right that a lot of software has some CPU bounds parts but I would argue that most code is IO bound. Usually there is a only a small kernel in a program that actually does heavy computation and this is the only place you should use threading.
- Coding_Cat 11y agoWhat's wrong with threading on IO? For example if you have a webserver which has to wait on replies from various other resources while serving enough clients to saturate itself. Sure, performance wise it is probably better to have a fixed number of threads which do their own scheduling in userspace but this requires much more work then a simple if(!finished()){yield();} and making a thread per client.
- jacques_chester 11y ago> What's wrong with threading on IO? To modify JWZ's famous joke: You have a problem. You say, "I know, I'll use threads!" Nowyou prob h2ave lems
- mystikal 11y agohaha, also: Now y