Develop 5 threads by using threads concept and make sure if any of 3 threads are completed out of 5 threads then kill other 2 threads

develop 5 threads by using threads concept and make sure if any of 3 threads are completed out of 5 threads then kill other 2 threads.

Hi @dave_59
Is it okay to use fine grain process here? What are the advantages of using semaphore instead of fine grain process?

Read the discussion that follows in the posted link.

Is this the right approach dave?

module tb;
    process p[5]; 
    int a = 0;
  event e1;
    initial begin
        fork
            begin
                p[0] = process::self();
              #($urandom_range(0,10));
                a++;
              $display("p[0].a=%0d",a);
              if(a>=3) 
                ->e1;
            end
            begin
                p[1] = process::self();
              #($urandom_range(0,10));
                a++;
              $display("p[1].a=%0d",a);
              if(a>=3) 
                ->e1;
            end
            begin
                p[2] = process::self();
              #($urandom_range(0,10));
                a++;
              $display("p[2].a=%0d",a);
              if(a>=3) 
                ->e1;
            end
            begin
                p[3] = process::self();
              #($urandom_range(0,10));
                a++;
              $display("p[3].a=%0d",a);
              if(a>=3) 
                ->e1;
            end
            begin
                p[4] = process::self();
              #($urandom_range(0,10));
                a++;
              $display("p[4].a=%0d",a);
              if(a>=3) 
                ->e1;
            end
        join_none 

      wait(e1.triggered);

        $display("Three threads have completed, terminating remaining at time %0t", $time);

        for (int i = 0; i < 5; i++) begin
            if (p[i].status == process::RUNNING) begin
                p[i].kill();
                $display("Thread %0d killed at time %0t", i+1, $time);
            end
        end

    end
endmodule

Please format your code making your code easier for others to read. I have done that for you.

This will probably work but suffers the same problem that the semaphore solves–multithreaded access to the shared variable ‘a’.