4 ms·
What if you need to do a compute intensive task on a large data structure? You know you might need to take advantage of more than one core and sharing memory be
by hacknat 11y ago
What if you need to do a compute intensive task on a large data structure? You know you might need to take advantage of more than one core and sharing memory between the threads will be difficult. Assuming you're talking about nodeJS, nodeJS serializes and deserializes objects in and out of C++ land in order to do compute intensive tasks. Hardly a catch all!
Are event loops good at some things? Of course! Are the good at everything. Are you high?
- zzzcpan 11y agoWell, no, I'm not talking about nodejs. Just in general, about event loops in programming languages. > What if you need to do a compute intensive task on a large data structure? That's a very specialized thing, not something general, that everyone needs. But either way there is no problem abstracting it away with higher order functions in event loops. However, everyone will most definitely need networking and doing networking by sharing memory between threads is very very hard. Event loops are much easier for that.
- jerf 11y agoEither your event handlers are going to be called in a nondeterministic order, or they won't. If they are going to be called in a nondeterministic order, you still have access control issues and can get yourself into all sorts of concurrency-style problems. If they aren't going to be called in a nondeterministic order, perhaps because you just have a single cascade of events (open socket, write this, get that, close socket), then in a language like Go you just write the "synchronous"-looking code, and you don't have to write the code as if it's evented. You have only marginally more sharing problems than the event loop. Raw usage of event loops are a false path. They solve very few problems and introduce far more.
- zzzcpan 11y ago> Either your event handlers are going to be called in a nondeterministic order, or they won't. The order is not going to be completely deterministic, but your whole program operates on explicitly deterministic units of computation that never implicitly execute in parallel (event handlers). This eliminates all of those issues with concurrent memory access. Writing "synchronous" looking code cannot be a substitute, since it makes these units of computation implicit. After which it's no longer possible to distinguish which function call is going to yield, therefore dealing with concurrent memory access is going to be needed, just like in any multithreaded program. So, no, event loops are superior to multithreaded model in almost every way.
- hacknat 11y ago>That's a very specialized thing, not something general While polling for i/o may be common the next most common problem in computers is solving computationally complex tasks. Why is Intel making all these cores? I guess no one actually needs them, they just think they do.