Does SystemVerilog assign a unique identifier to a process and is that accessible from user code?

I wonder whether SystemVerilog assigns a (unique) identifier to each process it generates, and whether that identifier is accessible from user code. Some (pseudo)code to show what I mean:


task f1;
  int id;
  begin
    id = get_process_id();
    $display("id: %d", id);
  end
endtask

f1();
fork
  f1();
  f1();
join
f1();

Expected output would then be something like
id: 0
id: 1
id: 2
id: 0

In SystemC, we can get a handle to the current process and e.g. ask for its name:


sc_core::sc_process_handle proc = sc_core::sc_get_current_process_handle();
std::string name = proc.name();

Is something similar possible in SystemVerilog?

In reply to basarts:

Yes, there is a built in process class that can give you a unique handle to the process. There is no string name associated with a process, but you could put handle into a queue or associative array. You can also use the initial randstate of the process

int plist[process];
int index;
task f1;
  process id;
  string name;
    id = process::self;
    plist[id] = index++;
    name = id.get_randstate();
    $display("id number: %d randstate: %s", plist[id], name);
  end
endtask

See section 9.7 Fine-grain process control in the IEEE 1800-2017 SystemVerilog LRM

In reply to dave_59:

Thanks Dave! I can definitely use the process handle. My simulator does not allow me to use a non-integer type as an index for an associative array, but I’ll work around that.