Controlling fork join_none threads execution

Hi,

I am struggling to understand, how to control the fork join_none threads launched as below:


while (outer loop) begin
  thread-x;
  fork
    thread-outer-1;
    thread-outer-2;
    thread-outer-3; 
  join_none

  while (inner loop) begin
    fork
      thread-inner-1;
      thread-inner-2;
      thread-inner-3;
    join_none
    wait fork;
  end
end

Here, I would like to wait for ONLY the thread-inner- to complete for the duration of the inner loop. Having wait fork, (I believe) waits for the thread-outer- also to complete, which is not what I want.

How can I “wait” only for the threads in the inner loop to finish, and then wait for the threads in the outer loop to finish before I start the next iteration of the outer loop?

Thanks,
Madhu

In reply to mseyunni:
In my opinion, the definition of the problem is insufficient. What is:

1.) duration of the inner loop?
2.) Do you intend to terminate the inner loops at the end of some duration? Or will they run to completion?
3.) In your last sentence you stated that you wanted to wait for the first iteration of the outer loop to complete before beginning the next iteration. If that is what you want, why do you need an inner and outer loop at all? Just fork the outer and inner loops off with a fork/join.

Ignoring my confusion…I would simply state that if you use fork/join instead of fork/join_none on the inner loops, then move the wait fork so that it executes after completion of the inner loop, that may be a solution, to a problem I don’t fully understand :)

In reply to dhserfer:

1.) duration of the inner loop?

Inner loops are expected to complete based on the handshake from the DUT, until then they will just have to wait/elapse the clock within their agent drivers.

2.) Do you intend to terminate the inner loops at the end of some duration? Or will they run to completion?

No, they are expected to complete as said in (1)

3.) In your last sentence you stated that you wanted to wait for the first iteration of the outer loop to complete before beginning the next iteration. If that is what you want, why do you need an inner and outer loop at all? Just fork the outer and inner loops off with a fork/join.

The reason for having two loops is, I have the stimulus such as a “frame” which is divided into blocks. The outer loop for example could be number of frames and the inner is number of blocks. My requirement is that I need to complete all the blocks in a frame, then wait for the other frame related threads to complete before starting next frame.

In reply to mseyunni:

Just use a fork/join instead of fork/join_none/wait fork in the inner loop.

while (outer loop) begin
  thread-x;
  fork
    thread-outer-1;
    thread-outer-2;
    thread-outer-3; 
  join_none
 
  while (inner loop)
    fork
      thread-inner-1;
      thread-inner-2;
      thread-inner-3;
    join
  wait fork;
end

In reply to dave_59:

Thank you Dave and dhserfer for answers. Yes. It works for my requirement. However, Can we use wait fork to control only one loop if there was such a requirement?

Thanks,
Madhu

In reply to mseyunni:

You can, but I don’t think the way you want to do it is much harder to follow

while (outer loop) begin
  thread-x;
  fork
    thread-outer-1;
    thread-outer-2;
    thread-outer-3; 
  join_none
 
  while (inner loop)
    fork begin
      fork
        thread-inner-1;
        thread-inner-2;
        thread-inner-3;
      join_none
      wait fork;
     end join
  wait fork;
end