class fork_join_task;
task fork_join_wait(int random_time);
fork: fork_1
begin
#random_time;
$display("process1 %t",$time);
end
begin
#20;
$error("Process 1 not completed at %t",$time);
end
join_any
disable fork_1; //giving label name,kill all process for wenever you call and different time to call
endtask
endclass
module fork_join;
fork_join_task c1,c2;
initial begin
c1=new();
c2=new();
fork
c1.fork_join_wait(10);
c2.fork_join_wait(30);
join
// #200;
$display($stime,"\t out side the fork");
// $finish;
end
endmodule
and I got output
process1 10
10 out side the fork
why can’t I use disable<label_name> instead of disable fork in this code?
In reply to Lokesh402:
Your disable fork_1; occurs after the join_any. There is nothing to disable.
See my updated model
fork: fork_1
begin
#random_time;
$display("process1 %t",$time);
end
begin
#20;
$error("Process 1 not completed at %t",$time);
end
begin #5 $display("after the #40"); end
begin #2 $display($stime,"\t inside the fork");
disable fork_1;
end
// join_any
join: fork_1
// disable fork_1; //
// fork_1; //giving label name,kill all process for wenever you call and different time to call
endtask
Sim results
# KERNEL: 2 inside the fork
# KERNEL: 2 out side the fork
It might have helped to explain the results you were expecting versus what you actually see.
disable label; kills any process executing under that label name. At the point you execute the first disable fork_1;, there are 3 active processes to be disabled, and the second disable fork_1 executes with nothing to disable.
disable fork; only kills the children of the process executing the disable command. So if you change to adisable fork; only 1 process forked by the c2.fork_join_wait(10) gets killed. The other process forked by the c1.fork_join_wait(30) will get to the #20 $error message.
Hi Dev,
Sorry i asked wrong way, actual doubt is
I have two objects(c1,c2) and one of object(c1) is called disable fork_1(label),but it’s disable fork join_any(fork_1) in all objects. why it’s disabled all the objects(disable fork_1 in c2)?
The disable construct terminates a process when applied to the named block or statement being executed by the process. The disable fork statement differs from disable in that disable fork considers the dynamic parent-child relationship of the processes, whereas disable uses the static, syntactical information of the disabled block. Thus, disableshall end all processes executing a particular block, whether the processes were forked by the calling thread or not, while disable fork shall end only the processes that were spawned by the calling thread.