0
$\begingroup$

I was referring to this page which defines fork, join and precedence graph as follows:

  • When the statement Fork(label) is executed by a thread of control, a second thread of control is started from the statement with the specified label. The two threads execute concurrently.
  • When the statement Join(count) is executed, where count is an integer variable, the value of count is decremented. If the resulting value is positive the executing thread is terminated.
  • A PRECEDENCE GRAPH is a directed, acyclic graph where nodes represent sequential activities and where arcs, say from node i to node j, require that activity i complete before activity j can start.

Base upon this I have been asked to draw precedence graph for a code containing fork and join constructs. For simple code, I can do. Also once given both code and precedence graph, I can see how the two correspond to each other. However when the code gets little bit complex, it becomes difficult to prepare precedence graph for me. Also doing reverse, from precedence graph preparing fork-join code is almost always difficult for me.

Can anyone give me intuitive stepwise procedure explaining how to obtain fork-join code from any given precedence graph?

Can we take example of following graph to apply the steps and get the fork and join code:

enter image description here

$\endgroup$
-1
$\begingroup$

x=2; y=2; z=2;

p1;

Fork L1 ; start p2

Fork L2 ; start p3

goto L3 ; stat P4

L1: p2;

fork L3 ;start p4;

goto L5

L3: join (x)

P4;

L4: join(y)

s6;

Quit();

L2 : P3;

L5: join(y)

 P5;  

 goto L4 
$\endgroup$
  • $\begingroup$ How does it answer the question? It was about the procedure to transcribe any graph, the given one is the example, but the mere code without any textual content is not sufficient explanation. $\endgroup$ – Evil Nov 24 '16 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.