top of page

Fork join

Estimated reading time: 10 mins

Consider the following SystemVerilog code snippet:

 

 

 

 

 


​

Correct Answer: 

Output 1:
Task B completed
Program completed
Explanation: Task B has the shortest delay of 5 time units, so it completes first. The "Program completed" message is then displayed.

Output 2:
Task C completed
Program completed
Explanation: Task C has a delay of 8 time units, which is shorter than Task A's delay of 10 time units. Therefore, Task C completes first, followed by the "Program completed" message.

Output 3:
Task A completed
Program completed

Easy Method to remember forks and joins: 

Imagine you are a manager of a small team working on a project. You assign three team members (A, B, and C) to work on separate tasks concurrently. Each team member represents a parallel statement in SystemVerilog.

  1. Fork-Join: In this case, you instruct all team members (A, B, and C) to start working on their tasks simultaneously. The team members work independently and complete their tasks. Once all team members have finished their tasks, they inform you, and you can proceed to the next step or check their progress. The key point here is that all team members need to complete their tasks before you can move forward.

  2. Join-Any: In this scenario, you assign the same three team members (A, B, and C) to work on their tasks concurrently. However, in this case, you are interested in the completion of at least one team member's task. Once any one of them completes their task, they inform you, and you can proceed to the next step or check their progress. The other team members may continue working on their tasks, but you don't need to wait for all of them to finish.

  3. Join-None: In this scenario, you assign the same three team members (A, B, and C) to work on their tasks concurrently. However, in this case, you do not need to wait for any team member to complete their task. Once you assign the tasks, you immediately move on to the next step or check something else, without considering the completion of their tasks.

Summarizing in single line: 

  1. fork-join: Executes the statements in parallel within the fork-join block, and all statements complete before proceeding to the next line of code outside the fork-join block.

  2. join_any: Waits until at least one of the parallel statements within the fork-join block completes before proceeding to the next line of code outside the fork-join block.

  3. join_none: Does not wait for any of the parallel statements to complete and proceeds to the next line of code outside the fork-join block immediately.

Code for above is at : https://edaplayground.com/x/Q58L

Also check, 

Interview questions for System Verilog (freshers) 

Interview Questions for UVM 

Interview Questions on Computer Architecture 

bottom of page