Fork/join

advertisement
CSC7103 Advanced Operating Systems - Assignment 2
Due Date: September 27, 2012.
1. Show by example that all precedence graphs cannot be implemented only by
cobegin/coend construct.
2. Write a simple program that will accept a precedence graph as input and generate
the corresponding program using fork/join.
3. Write a program that will enable you to compare the average creation time of a
new process with the creation time of a thread in user space. Note that to compute
averages you will need to run the program(s) several times. Provide all the details
in the form of tables.
Fork/join
Fork: The fork system call for this assignment has one parameter, viz., a label. Fork
creates an identical copy of the calling process, which begins execution at the label.
Join: The join system call has one parameter, viz., an integer. Join decrements the integer
by one. If the value of the integer after decrement is non-zero, the process terminates.
Otherwise the process continues execution with the next statement.
Example: The fork/join implementation of a precedence graph is shown below.
S
S1
S2
S3
S4
S6
S5
S7
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;
Cobegin/coend
The Cobegin/coend construct allows concurrent execution of all program blocks
enclosed. At cobegin all program blocks begin concurrent execution and at coend all of
them must complete execution before the next block may begin execution.
Example: The cobegin/coend implementation of a precedence graph is shown below.
S1
S2
S3
S4
S5
S6
S7
begin
S1;
cobegin
S3;
begin
S2;
cobegin
S4;
S5;
coend;
S6;
end;
coend;
S7;
end;
Download