Resume simulation when any 2 threads out of 3 get completed within fork-join_any

In reply to Sagar Shah:
You can use a semaphore that waits for 2 keys

semaphore s;

s = new(0);
fork
   begin : process1
    ...
    s.put(1);
   end
 begin : process2
    ...
    s.put(1);
   end
 begin : process3
    ...
    s.put(1);
 end
join_none
s.get(2);
disable fork; // kills remaining process
s = null; // removes semaphore (if you plan to reuse s)

2 Likes