The Ultimate Hitchhiker's Guide to Verification

Dumping ground of useful links/articles/tips/tricks on System Verilog/VMM/OVM as and when I stumble upon them and some of my views on it :)

All about fork-join of System Verilog

I have added histstat hit counter for my blog to have an idea about traffic/visitor/search engine trends. One interesting I am observing is that quite a few hit to my site is coming for fork/join interview questions in Google. Hence I thought, why not have a real useful post on fork/join{x} of SystemVerilog and its associated disable/wait command.

Fork-join statement has come from Verilog. It is used for forking out parallel processes in test bench. SV substantially improved fork/join construct to have much more controllability in process creation, destruction, and waiting for end of the process.

The basic syntax of fork join block looks like this:

fork
   begin : First_thread
       // Code for 1st thread
   end
   begin : Second_thread
       // Code for 2nd thread
   end
   begin : Third thread
       // Code for 3rd branch
   end
   ...
join    // Can be join_any, join_none in SV

There are 3 different kind of join keyword in SV, each specifying a different way of waiting for completion of the threads/process created by the fork.
  • join : waits for completion of all of the threads
  • join_any : waits for the completion of the 1st thread, then comes out of fork loop, but lets the other process/thread execute as usual
  • join_none : doesn't wait for completion of any thread, just starts then and immediately exits fork loop.
Now, suppose you have exited the fork loop by join_none or join_any and after some steps, you want to wait till completion of all the threads spanned by the previous fork loop. SV has "wait fork" for the same.

Now, suppose you have exited the fork loop by join_none or join_any and after some steps, you want to kill all the threads spanned by the previous fork loop. SV has "disable fork" for the same.

Next interesting scenario: you have exited fork loop by join_none or join_any and after some steps, you want to kill just one thread (out of many). The solution, have named begin end block and call "disable ". (For example, in the last example if you want to kill only the 2nd thread after exiting the loop via join_any/join_none, then add "disable Second_thread;" at the point where you want to disable the second thread.

I have created a image to pictorially depict fork/join in SV. Hope that will help understand this in a much better way.

0 comments:

Post a Comment

About Me

My photo
I am from Sambalpur, Orissa, India. Have done Btech and Mtech in ECE from IIT Kharagpur. Currently working as Lead Member Technical Staff at Mentor Graphics Noida

My Feedburner

Followers

Search This Blog

My Shelfari Bookshelf

Shelfari: Book reviews on your book blog

 

Traffic Summary