I saw someone writing the following code:
event_done[N_GENERATORS];
int done_count;
initial begin
foreach (gen[i]) begin
gen[i] = new(done[i]);
gen[i].run();
end
foreach (gen[i])
fork
automatic int k = i;<font size=20>
begin
wait (done[k].triggered);
done_count++;
end
join_none
wait (done_count == N_GENERATORS);
end
How does done_count work in this code? couldn’t it happen that two threads could modify the global done_count variable at the same which causes race condition?