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 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
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