Fine grain process control

Hi ,

I was trying to print the spawned process of fork/join_none using process class :: status but not able to achieve it could you please help
code:

module test;

std::process active_p[$];

std::process::state pstate;

initial begin

fork

begin
$display(“[%0t] start for thread 1”,$time);
active_p.push_back (std::process::self());
#1;
$display(“[%0t] end for thread 1”,$time);
end

begin
$display(“[%0t] start for thread 2”,$time);
active_p.push_back (std::process::self());
#2;
$display(“[%0t] end for thread 2”,$time);
end

begin
$display(“[%0t] start for thread 3”,$time);
active_p.push_back (std::process::self());
#3;
$display(“[%0t] end for thread 3”,$time);
end

join_none

foreach(active_p[i])
$display(“status for process[%0d]:%s”,i,p[i].status.name());

wait fork;

end
endmodule:test

link:

Thanks in advance

The issue in your code arises because you are checking the process status immediately after fork/join_none. At that point, the forked processes may not have started execution yet.

To resolve this, introduce a small delay before checking the process status. This ensures that the spawned processes have had enough time to start, allowing the status check to reflect the correct state.

Example link :
https://edaplayground.com/x/a8QD

Thank you

Is there any other way other than adding delay. please let me know

Instead of the delay, use:

wait ( active_p.size() == 3 )