Fork join question if we need to disable fork in some condition

Here is requirements : we have two process and spawned together in one fork-join. what we need is if processB is completed, then we disable the fork and jump out the fork-join. How to write it ?

fork
   begin
       processA();
   end
   begin
       processB();
       disable fork;
   end
join

above code is not correct I guess…

You want to use the built-in process class (Section 9.7 Fine-grain process control in the IEEE 1800-2023 SystemVerilog LRM).

process pA;
fork
   begin
       pA = process::self();
       processA();
   end
   begin
       processB();
       pA.kill();
   end
join

Thanks Dave. I will take a try.

Hi Dave! The original code ideally should work too, right?

If there are other child-thread spawned in processA(), for example we connect a sequencer with a driver inside processA and the item started at a certain point, how to kill it when processB() completed ? I mean if pA.kill() will kill all child process inside processA() ?

It does not work because the first process is not a child of the process executing the disable fork statement.

Now you’ve brought UVM into the picture. It’s generally a bad idea to kill or disable a sequence thread. It could leave the driver in a messup up state. I would do a search for “proper way to kill a sequence”

Hi Dave, Got your point. It should ideally work if i disable the main fork join block by naming it?

fork : main_blk
   begin
       processA();
   end
   begin
       processB();
       disable main_blk;
   end
join

It works if there’s only one instance of the main_blk. However, the problem with disabling named blocks is that it disables all invocations of those blocks.

1 Like

Hi @dave_59,

Is there any option or way to create the name/tag of the block to include ID which would be incremented upon each invocation of this block?

e.g. we have a UVC agent, which we have 10 instances of it in our TB.
Each UVC will have a unique index.
Ideally the name of fork block would include in its name - the unique index of the UVC.

Use the process class instead of named blocks.