Fork join threads in a sequence body

Hi,
I have a below code(simplified version of actual code).
Main Thread 1 - meant to drive ready on all the 8 inbound agents. The corresponding seq runs forever. It looks fine.

Main Thread 2 - meant to run multiple sequences on a random outbound agents parallel to above and the parent thread should exit once these grandchild sequences are completed. But I see that all the grandchild sequences(=no_of_seq) are spawn but they seem to run continuously. Test doesn’t fail with timeout since a RTL assertions is reported. Debug messages indicate that the grand sequences spawn in “Main Thread 2” seem to run for more than expected time without setting ‘end’ signal. I may have to debug it further, but the issue seem to be in the way threads are spawn(it works fine with jsut 1 grandchild sequence). So wanted to check.

How can I fix this to run as intended? TIA

fork : rdy_and_other
   begin //---------Main Thread 1----------------	    
      for (int k=0; k<NUM_AGENTS;k++) begin   
         fork
	    int i = k;
	    rdy_seq[i].randomize();	
	    rdy_seq[i].start(p_sequencer.ib_agent_sequencer[i]);	       	
         join_none	     
      end // for           
      
   end //----------Main Thread1-----------------
   begin //------------------Main Thread2----------------------
      fork  begin : isolating_fork  
	 for (int p=0; p<no_of_seq; p++) begin
	    fork :ib_ob_agents
	       begin
		  a = ....;
		  b = ....;
		  ob_agent_num = $urandom_range(0,7);		  
		  ob_seq[ob_agent_num].randomize;
		  ob_seq[ob_agent_num].start(p_sequencer.ob_agent_sequencer[ob_agent_num]); 		  
	       end //fork 

	    join_none : ib_ob_agents	  
         end // for  
         wait fork;
      end  : isolating_fork
      join // isolating fork
   end // //------------------Main Thread 2----------------------
join_any : rdy_and_other  

In reply to sdesai:

One thing your simplified code does not show is construction of the sequences. Every sequence you start needs to be newly constructed. This especially true if ob_agent_num gets repeated.

You probably should have ob_seq be an array of uvm_object_wrapper objects instead of the actual sequence objects.

               begin 
                  your_sequence_base seq;
		  a = ....;
		  b = ....;
		  ob_agent_num = $urandom_range(0,7);
                  $cast(seq,ob_seq[ob_agent_num].create_object(...);  
		  seq.randomize;
		  seq.start(p_sequencer.ob_agent_sequencer[ob_agent_num]); 		  
	       end

See this link for more examples of uvm_object_wrapper.

In reply to dave_59:

You were right, sequence construction was not inside. I did move it inside. But it didn’t change anything. The ob_agent_num generated were unique(they were 5) and none repeated. So, it didn’t make any difference to the simulation. Probably I need to debug is further.

I did try below code,

begin 
                  your_sequence_base seq;
		  a = ....;
		  b = ....;
		  ob_agent_num = $urandom_range(0,7);
                  $cast(seq,ob_seq[ob_agent_num].create_object("");  
		  seq.randomize;
		  seq.start(p_sequencer.ob_agent_sequencer[ob_agent_num]); 		  
	       end
``` verilog






But it reports, " Null object access, The object is being used before it was constructed/allocated"  at below line. Do I have to specify anything in those quotes or anything is missing?
                  $cast(seq,ob_seq[ob_agent_num].create_object("");  


 There is always something to learn from your posts. Thank you!

In reply to sdesai:

You need to place an object in ob_seq[ob_agent_num] with an object returned from my_seq::get_type(). Look at the link I gave you.

In reply to dave_59:

I had checked it though. Anyway will check again.
I could debug and the issue seemed to be with one of the sequence fields generation. Specific to our protocol. Thank you!