Break out of while loop after certain timeout

Hi,

I’m a newbie to OVM. I’m trying to break out of a while loop after a fixed timeout of 120us. Here is the loop that I have:
while(signal_val1 ==0) begin
signal_val1 == sla_vpi_get_value_by_name (“blah”);
end

This code is part of an OVM test and I want to restrict the check happening in my ‘while’ loop for 120us after which I want the test to exit. I’ve tried doing this by adding conditions within the while loop, a for loop around it, ‘set_global_timeout()’, etc., but none of them work. I figured that I will have to call my ‘global_stop_request()’ if I want the test to quit, but how do I check for this 120us (120 microseconds) condition and exit from the loop?

Kindly help!! Thanks in advance!

In reply to nik_88:

You use fork/join_any for this

fork 
   looping_code; //process 1
   #120us;       //process 2
join_any
global_stop_request();

The statement after the join_any starts when any one of the processes inside the fork/joia_any completes. You can also use disable fork to kill any remaining processes.

There is a problem with your while loop though - it will gointo an infinite 0 delay loop when signal_val == 0 is true. You need a blocking statement inside the loop so time can advance.

In reply to dave_59:
@dave_59 - Yes the condition in the while loop: signal_val ==0 actually never becomes true. That’s the reason I want to exit from the loop and quit the test after checking for a 120 microsecond period. Thanks for your reply - I had a few questions though. Should the global_stop_request() be called outside the fork? Would anything change for a disable process? Can you show me how disable would work here and which is better to use? I’ll try this suggestion and get back with any comments or let you know if it works.

In reply to dave_59:
@dave_59: ‘fork-join_any’ is not being recognized as a valid syntax. I get an error at join_any. Only fork-join seems to be valid for the compiler. What do I do?

In reply to nik_88:

In reply to dave_59:
@dave_59: ‘fork-join_any’ is not being recognized as a valid syntax. I get an error at join_any. Only fork-join seems to be valid for the compiler. What do I do?

Sorry about this comment, my bad. The join_any does look good. The earlier error I got was due to something else in the code. @dave_59 - is there a way to add a print message in the code you suggested to check which process ended first in the fork-join_any?