How to mutex the task

In reply to dave_59:

Thanks Dave. It works.

what I tried before is below. but it didn’t work. could you please give me a hint why not worked ? (I have a bit variable named mutex in this class)


bit mutex = 1;



task A(int i);

wait(mutex);
mutex = 0;

case (i)
  1 : begin
      B(…);
  end
  2 : begin
      B(…);
  end
  3: begin
     B(…);
  end
...
...

mutex = 1;

endtask : A