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