Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Fork and Join Constructs in Concurrency

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Prerequisite – Process Synchronization
Fork :
The fork instruction is the that instruction in the process execution that produces two concurrent executions in a program. One of the concurrent executions starts at statement labeled and other execution is the continuation of the execution at the statement following the fork instruction. The fork systems call assignment has one parameter i.e. Label (L).

Join :
The join instruction is the that instruction in the process execution that provides the medium to recombine two concurrent computations into a single one. The join instruction has one parameter integer count that specifies the number of computations which are to be joined. It decrements the integer by one. If the value of the integer after decrement is non-zero then the process terminates otherwise the process continues execution with the next statement.

Example-1:
Construct the precedence graph for the following fork/join program.

     S1;
     count1: = 2;
     fork L1;
     S2;
     S4;
     count2: = 2;
     fork L2;
     S5;
     Go to L3;
L1:  S3;
L2:  join count1;
     S6;
L3:  join count2;
     S7;

Solution :

Example-2 :
Write a fork/join program for the following precedence graph.

Solution :
After S1 fork statement is required to create a child.
After S4 fork statement is required to create a child.
All processes need to join before S7.

     S1;
     count: = 3;
     fork L1;
     S2;
     S4;
     fork L2;
     S5;
     Go to L3;
L2:  S6;
     GOTO L3;
L1:  S3;
L3:  join count;
     S7; 
My Personal Notes arrow_drop_up
Last Updated : 06 Jul, 2020
Like Article
Save Article
Similar Reads