What happens to threads that don't finish



function void get_client_request();

for(int i=0;i<NUM_INTF;i++)begin
  automatic int client = i;
  fork
    begin
      clnt_fifo[client].get(current_req);
    end
  join_none 
end
endfunction

I’m using the function get_client_request() to collect requests into my client fifos. Every client has its own analysis fifo(that’s why I’m using clnt_fifo[client].get()). I know that the current request will only go into one client at a time so the get() will be successful for only one of the clients for every request. What will happen to the other (NUM_INTF-1) threads of the other clients? Will their get() be blocked indefinitely and hence, those threads will never finish? If this function gets called 10 times for 10 incoming requests, at the end of the 10 iterations will there be 10*(NUM_INTF-1) unfinished threads? If yes, will these threads be killed at the end if the simulation?

Note: clnt_fifo is an array of uvm_tlm_analysis_fifo

In reply to vikrant_sharma:

When you spawn a thread with fork/join_none, there are a number of ways that thread can terminate:

  • The statements in that thread complete.
  • The parent thread (the thread calling get_client_request()) or any of its ancestors executes a disable fork statement.
  • You call the kill() method of the thread handle you obtained using process::self().
  • The simulation terminates.

You probably don’t want to have a lot of extra threads running around; it can make debugging difficult and there might be other problems if there is more to your code than shown here. A better option would be to call get_client_request() once and put each forked thread into a forever loop.