3 ms·
Any code example? In this model I think deadlocks is possible, like in CSP. I wonder if CSP is closer to this model, right?
by mamcx 9y ago
Any code example?
In this model I think deadlocks is possible, like in CSP. I wonder if CSP is closer to this model, right?
- chrisseaton 9y agoNo CSP is all about mutable state in each process. Fork-join looks like, where we blur an image with two-way parallelism: a, b = divide image into halves fork { a' = blur a b' = blur b } result = combine halves a' b' So all the tasks in the fork { } block run in parallel. The task that created those tasks stops and waits for them to all finish and to have all their results before it continues. And there's no way the order of the tasks finishing can change the result because you always have to wait for all your tasks to finish. See how there's no mutable state? You can only start a task, and accept its result. You can't see or change anything in between that. You can get a deadlock if one task crashes. Some people really care about that, some people see it as an implementation detail and wouldn't really define it as a 'deadlock' in the same way.
- kuschku 9y agoSo, you basically have what JS calls await Promise.all(a, b) ?
- chrisseaton 9y agoYes you can build fork-join that way, but you'd need to remember to manually follow some rules. You should create the tasks a and b immediately before you await, and do no other work between creating them and awaiting. And you should not cause any side effects in the two tasks. Systems which have fork-join built-in would either help you to follow those rules, or force you to.
- mamcx 9y agoSo, if I understand, you "tasks" are almost pure functions: fork -> send -> task1(input) & task2(input) -> joiner And you must always(?) have a join? so I can't have a zombie task elsewhere? I probably like how this sound! Exist a more detailed material to study on this?