Fork Question

bcomputer

Beta member
Messages
1
Location
United States
I'm not really sure how this fork() method works in java. For example, here's some pseudocode:

main () {
******* fork();
******* fork();
******* fork();
******* print “DONE”;
}


What would be the outcome of that?
 

strollin

Knowitall!
Messages
3,448
Location
N. Calif.
The pseudocode would look more like:

main() {

join() {
fork();
fork();
fork();
}
print "Done";
}

There needs to be a way for the code to know when the forked processes are complete so the join does that. It's more complicated than that but that's the gist of it.

This is the way it's usually explained:

Code:
Result solve(Problem problem) {
    if (problem is small)
       directly solve problem
    else {
       split problem into independent parts
       fork new subtasks to solve each part
       join all subtasks
       compose result from subresults
    }
}
 
Top