Creating a timed_wait task

Hi,
A large number of tasks inside my testbench wait for events. I would like to create a macro wrapper so that if the task does not complete within a timeout time then i would like to disable the task. Is that possible?

My first attempt at creating a macro gives syntax error. Not sure how to do it or whether it is even possible?

`define timed_task(taskname, timeout) \
   do begin \
    fork begin \
      fork: my_block \
        taskname(); \
        #(timeout) $fatal("[%0t]:Timeout taskname %s", $stime, taskname); \
      join_any \
      disable fork; \
    end join \
   end while(0)

-sanjeev

In reply to sanjeevs:
It would help to provide a minimal complete example, and show us the error message you are getting.

A do-while statement requires a semi-colon, but maybe you had it in your actual code. But there is no need for a do-while; the fork-begin-end-join should provide the encapsulation you need.

To print the taskname as a string, you need to write it as

 #(timeout) $fatal("[%0t]:Timeout taskname %s", $realtime, `"taskname`"); \

You should use $realtime to get any fractional time

In reply to dave_59:

Thanks. That worked.