3 ms·
IO calls. Concurrency matters only if your threads are doing IO. Otherwise it's useless to use goroutines. Lets say an IO call to high latency connection takes
by crimsonalucard 8y ago
IO calls. Concurrency matters only if your threads are doing IO. Otherwise it's useless to use goroutines.
Lets say an IO call to high latency connection takes 4 seconds. With no concurrency in between that IO call the program just sits and waits for a response. Under concurrency the program can switch to another thread while it's waiting for the IO call to complete.
- gpderetta 8y agoIt is not just for io. If a system is better modelled with a set of indipendent execution flows exchaging messages (a simulation for example), then coroutines are perfect. Games often use coroutines to model game entities: it is not a coincidence that lua has excellent coroutine support.
- crimsonalucard 8y agoRight, except that's not what's happening in reality no matter how you model it. Having your code mimic the actual pathway of execution rather than the overhead of simulating parallelism is more efficient. Typically multithreading adds way more complexity and a whole new class of bugs to the code.