Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

System verilog, fork join_any

Status
Not open for further replies.

surerdra

Junior Member level 1
Joined
Feb 15, 2014
Messages
18
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
237
Can any one please tell me,


Generally the "Fork join_any" is work like, if any one of the internal task can finished, it will non blocked the next statements.


My question is if i taken three tasks in "fork join_any", it has to wait for any two tasks can complete, then only it come out side of fork join_any


how it is ?
 

If you have tasks a, b, and c then if a takes 10, b task 2, and c takes 5 time units then the fork-join_any will exit when task b finishes (FYI a and c will still run to completion) and continue on to whatever follows the fork-join_any.

In other words the first block that finishes causes the join to occur, hence the name join_any. You can think of the Verilog fork-join as join_all

Here is an example:

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
`timescale 1ps/1ps
module fork_join_any;
 
localparam ns = 1000;
 
bit clk;
always #(5*ns) clk = ~clk;
 
 
initial begin
 
  $display ("Starting fork-join_any test");
 
  fork
 
    begin
      repeat (10) @(posedge clk);
      $display ("Finished repeat (10)");   
    end
 
    begin
      repeat (4) @(posedge clk);
      $display ("Finished repeat (4)");   
    end
 
    begin
      repeat (7) @(posedge clk);
      $display ("Finished repeat (7)");   
    end
 
  join_any;
 
  $display ("Exiting fork-join_any");
 
  repeat (8) @(posedge clk);
 
  $display ("Finished fork-join_any test");
  $finish;
 
end
 
endmodule



Which has the following output:
Code:
# Starting fork-join_any test
# Finished repeat (4)
# Exiting fork-join_any
# Finished repeat (7)
# Finished repeat (10)
# Finished fork-join_any test
# ** Note: $finish    : fork_join_any.sv(38)
#    Time: 115 ns  Iteration: 1  Instance: /fork_join_any
# End time: 08:03:23 on Jun 04,2019, Elapsed time: 0:00:06
# Errors: 0, Warnings: 0
 

You will need to use a semaphore
Code:
[FONT=Courier New]semaphore s;
 
s = new(0);
fork
   begin : process1
    ...
    s.put(1);
   end
 begin : process2
    ...
    s.put(1);
   end
 begin : process3
    ...
    s.put(1);
 end
join_none
s.get(2);
disable fork; // kills remaining process
s = null; // removes semaphore (if you plan to reuse s)[/FONT]
 

the semaphore method is good

Thank you
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top