Using automatic variables inside a fork - join_none

Hi:
How do I re-write the code shown below, using a for loop and automatic variables?
Thank You!



task class_c::clear(); 
   begin 

   fork 

         forever begin 
            @(this.incoming[0]); 
            if (this.incoming[0] == 1) begin  
               #5ns; 
               this.incoming[0] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[1]); 
            if (this.incoming[1] == 1) begin  
               #5ns; 
               this.incoming[1] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[2]); 
            if (this.incoming[2] == 1) begin  
               #5ns; 
               this.incoming[2] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[3]); 
            if (this.incoming[3] == 1) begin  
               #5ns; 
               this.incoming[3] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[4]); 
            if (this.incoming[4] == 1) begin  
               #5ns; 
               this.incoming[4] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[5]); 
            if (this.incoming[5] == 1) begin  
               #5ns; 
               this.incoming[5] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[6]); 
            if (this.incoming[6] == 1) begin  
               #5ns; 
               this.incoming[6] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[7]); 
            if (this.incoming[7] == 1) begin  
               #5ns; 
               this.incoming[7] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[8]); 
            if (this.incoming[8] == 1) begin  
               #5ns; 
               this.incoming[8] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[9]); 
            if (this.incoming[9] == 1) begin  
               #5ns; 
               this.incoming[9] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[10]); 
            if (this.incoming[10] == 1) begin  
               #5ns; 
               this.incoming[10] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[11]); 
            if (this.incoming[11] == 1) begin  
               #5ns; 
               this.incoming[11] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[12]); 
            if (this.incoming[12] == 1) begin  
               #5ns; 
               this.incoming[12] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[13]); 
            if (this.incoming[13] == 1) begin  
               #5ns; 
               this.incoming[13] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[14]); 
            if (this.incoming[14] == 1) begin  
               #5ns; 
               this.incoming[14] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[15]); 
            if (this.incoming[15] == 1) begin  
               #5ns; 
               this.incoming[15] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[16]); 
            if (this.incoming[16] == 1) begin  
               #5ns; 
               this.incoming[16] = 0; 
            end   
         end  
         forever begin 
            @(this.incoming[17]); 
            if (this.incoming[17] == 1) begin  
               #5ns; 
               this.incoming[17] = 0; 
            end   
         end  

   join_none 

   end  
endtask: clear


In reply to new_to_uvm:

I wish to do something similar with this code.
Thank You!


task class_c::start_something (); 

   begin 
   
      forever begin 
         @some_event;
   
         fork 
               if (this.pi[0] == 1)  start_operation [0] = 1;
               if (this.pi[1] == 1)  start_operation [1] = 1;
               if (this.pi[2] == 1)  start_operation [2] = 1;
               if (this.pi[3] == 1)  start_operation [3] = 1;
               if (this.pi[4] == 1)  start_operation [4] = 1;
               if (this.pi[5] == 1)  start_operation [5] = 1;
               if (this.pi[6] == 1)  start_operation [6] = 1;
               if (this.pi[7] == 1)  start_operation [7] = 1;
               if (this.pi[8] == 1)  start_operation [8] = 1;
               if (this.pi[9] == 1)  start_operation [9] = 1;
               if (this.pi[10] == 1) start_operation [10] = 1;
               if (this.pi[11] == 1) start_operation [11] = 1;
               if (this.pi[12] == 1) start_operation [12] = 1;
               if (this.pi[13] == 1) start_operation [13] = 1;
               if (this.pi[14] == 1) start_operation [14] = 1;
               if (this.pi[15] == 1) start_operation [15] = 1;
               if (this.pi[16] == 1) start_operation [16] = 1;
               if (this.pi[17] == 1) start_operation [17] = 1;
         join_none  
      end
   
   end  

endtask: start_something

In reply to your first post new_to_uvm:

task class_c::clear(); 
   foreach(incoming[i])
         fork : foreach_loop 
           int j = i;
           begin 
             wait (incoming[j] == 1);  
             #5ns; 
             incoming[j] = 0; 
           end   
          join_none : foreach_loop
   wait(0); // your posted code never exits; not sure if that's what you want
endtask        

In reply to your second post new_to_uvm:
There is no need to use a fork statement unless you have a time consuming process to fork. Your posted code would simply be

task class_c::start_something (); 
     forever  @some_event foreach(pi[i]) start_operation [i] = 1;
endtask


In reply to dave_59:

Thank You Dave!

In reply to dave_59:

Thank You Dave!
Yes, I wanted the forever begin in there.