Tuesday, August 17, 2010

disable fork will disable the respected fork threads

Dear ChipMates,

Here I came across interesting exercises with fork join, I was using fork join thread in my complex verification environment where I was playing with so many fork join threads. I was having child forks inside parent forks.

System Verilog has a strong construct called 'disable fork' through which engineer can control the fork processes. SV has three different fork processes, 1. fork-join 2. fork-join_none 3. fork-join_any. From which fork-join_none and fork-join_any needs process control because normal fork-join will comes out only when all the processes will be executed and done. But join_any will comes out when any of the process will finish its job. These places some times we need process control and we may need to disable fork thread once perticular process is done.

I have made simple exercises (given below) which will give you idea how to control fork-join with disable fork construct in System Verilog.

program test ;
class A ;
   task fork_join ();
      int temp = 1;
                  if (temp == 1)
                 $display ("Inside first Begin...end thread \n");
                  # 100ns;
                  $display ("Inside second Begin...end therad\n");
           disable fork; // This will disable only child fork
           # 50ns;
           $display ("Inside Second thread of main fork \n");

   A aa = new ;

From the above given will pring below given messages :

Inside first Begin...end thread

Inside Second thread of main fork

From the messages it seems, it has disabled the child fork proecess not the mail fork process, and as a result we are able to see second message called "Inside Second thread of mail fork"

Hope this was a useful sharing for all.

Happy Reading,
ASIC with Ankit