I have 3 tasks T1, T2, T3 which are called in fork and i want to come out of the for when any 2 of the 3 tasks are completed. (t1t2 or t2t3 or t3t1. when either one of these combinations occurs i need to come out of the fork join_xx)
Which fork join_xx should i use and make it work for any combination.
fork
T1 ;
T2 ;
T3 ;
join_xx // exit when any of the 2 are completed
In reply to Varun Marichi:
For this there is no direct way you can use something like this:
bit a,b,c;
fork
begin
T1;
a = 1;
wait( b || c);
end
begin
T2;
b = 1;
wait(a || c);
end
begin
T3;
c = 1;
wait(a || b);
end
join_any
In reply to nikhil_c:
Thank you. I was actually expecting a direct solution by using the variations in fork join but thank you for this solution. But i think on this line we can also use semaphores in place of the bits
module fork_join_process();
semaphore sema ;
task automatic print_value;
input [7:0] value;
input [7:0] delay;
begin
sema.get(1);
#(delay) $display("@%g Passed Value %d Delay %d",
$time, value, delay);
sema.put(1);
end
endtask
initial begin
sema=new(3);
fork
#1 print_value (10,7);
#1 print_value (8,5);
#1 print_value (4,2);
join_any
$display("@%g Came out of fork-join", $time);
sema.get(2);
$display("@%g 2 tasks finished", $time);
#20 $finish;
end
endmodule