In reply to yakirye:
Yes, what you wrote works under one condition—there is only one invocation of my_task. If there are multiple invocations, disable sec_fork kills all of them.
There are a couple better ways of coding this. You can put a fork/join as a process guard.
task my_task()
fork : first_fork
task1;
task2;
join_any : first_fork
fork
begin : sec_fork_guard
fork : sec_fork
task3;
task4;
join_any : sec_fork
disable fork; // only disable inside sec_fork_guard block
end : sec_fork_guard
join
endtask : my_task
And for complete control, you can use the process class
task my_task()
process p[$];
fork : first_fork
task1;
task2;
join_any : first_fork
fork : sec_fork
begin
p.push_back(process::self();
task3;
end
begin
p.push_back(process::self();
task4;
end
join_any
foreach(p[i]) if (p[i].status != process::FINISHED) p[i].kill();
endtask : my_task