Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAP PROLOG timeout issue

Tags:

prolog

yap

Can anyone explain why the following YAP code does not result in the variable Result being unified with time_out?

?- time_out(sleep(3),1,Result).
Result = success.
?- time_out(sleep(3),2,Result).
Result = success.
 ?- time_out(sleep(3),1000,Result).
Result = success.
 ?- time_out(sleep(3),2000,Result).

According to the documentation, the predicate should work as follows:

time_out(+Goal, +Timeout, -Result)

Execute goal Goal with time limited Timeout, where Timeout is measured in milliseconds. If the goal succeeds, unify Result with success. If the timer expires before the goal terminates, unify Result with time_out.

like image 985
S0rin Avatar asked Jan 18 '26 03:01

S0rin


1 Answers

YAP's documentation also states that:

Last, even though the timer is set in milliseconds, the current implementation relies on alarm/3, and therefore can only offer precision on the scale of seconds.

In turn, the documentation for sleep/1 states:

Block the current thread for Time seconds.

But the problem in this case is likely not related to the times but for the call to sleep/1 blocking the current thread where the time_out/3 call is being itself executed. Nevertheless, I tried the time_out/3 predicate with other goals and also couldn't not get the expected time out. Thus, there might be some bug in it.

like image 68
Paulo Moura Avatar answered Jan 19 '26 19:01

Paulo Moura



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!