-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfork.sv
66 lines (55 loc) · 1.26 KB
/
fork.sv
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$display("A");
fork
$display("B");
#50; $display("C");
begin
$display("D");
#30 $display("E");
#10 $display("F");
end
join_any
$display("G");
// A B D E F G C
fork:f1
#300 $display("thread 1");
#350 $display("thread 2");
begin
fork: f2
#350 $display("thread 3");
#200 $display("thread 4");
join_none
#170 begin disable fork;
$display("disable fork");
end
end
#300 $display("thread 5");
join_none
// only the thread 3,4 will be disabled, since we have the encapuslation for the f2
// task is static; function is automatic !!BY DEFAULT!!
for(inti=0;i<=10;i++)
begin
fork
automatic int j=i; //note you must declare a automatic copy of j here other wise it will be same value(10) when you spawn all some_task()
begin
printsomething;
some_task(j);
end
join_none
end
// task varible also static in default, if no "automatic" added, the output is:
// #11ns 20
// #20ns 20
task print(automatic i);
#10ns;
$display("%s ns %d", $time, i);
endtask
initial begin
fork
begin
#1ns;print(10);
end
begin
#10ns;print(20);
end
join
end