3 ms·
Honest question: If you aren't going to share data between/among threads, why use threads at all? Why not just fork-abd-exec?
by fnj 9y ago
Honest question: If you aren't going to share data between/among threads, why use threads at all? Why not just fork-abd-exec?
- danieltillett 9y agoBecause on windows it is much slower.
- to3m 9y agoIf it's the same, it's the same, so there's no reason to do one rather than the other. Why not just create a thread?
- thristian 9y agoSharing (immutable) data between threads is fine, you just don't want to share (mutable) state or else you run the risk of threads stomping on each other. The ideal scenario is map/reduce: you take some large chunk of data, divide it up into smaller chunks, spin up a thread to process each smaller chunk and produce a result. Once the threads have all completed and the results are no longer changing, the main thread can pick them up and combine them to a single result. It's possible to do that with fork-and-exec, but without a shared address space, marshalling costs make it expensive.