(Somehow I missed this thread)
First, sleep/1
and time_out/3
do not flock together. time_out/3
waits for a certain amount of milliseconds of CPU-time or thread-time, whereas sleep/1
sleeps real-time seconds. There are certain limitations in YAP compared to the original in SICStus, see the manual for more.
In the current development version from the git (last commit d5ce9a137668fe1ae34e2d47c91fc2725ae04a5f,
Date: Wed Apr 22 14:21:20 2015 -0600), the mechanism seems to be broken.
In an older version of 6.3.4 I get:
YAP 6.3.4 (x86_64-linux): Tue Jan 29 12:39:29 CET 2013
MYDDAS version MYDDAS-0.9.1
?- use_module(library(timeout)).
% reconsulting /opt/gupu/share/Yap/timeout.yap...
% reconsulting /opt/gupu/share/Yap/hacks.yap...
% reconsulted /opt/gupu/share/Yap/hacks.yap in module yap_hacks, 0 msec 15472 bytes
% reconsulted /opt/gupu/share/Yap/timeout.yap in module timeout, 0 msec 48240 bytes
true.
?- 100000000=J,time(time_out((between(1,J,N),N=J),1,R)).
% 0.008 CPU in 0.007 seconds (114% CPU)
J = 100000000,
R = time_out.
?- 100000000=J,time(time_out((between(1,J,N),N=J),10000,R)).
% 9.985 CPU in 10.003 seconds ( 99% CPU)
J = 100000000,
R = time_out.
?- 100000000=J,time(time_out((between(1,J,N),N=J),100000,R)).
% 23.477 CPU in 23.522 seconds ( 99% CPU)
J = N = 100000000,
R = success.
?- 100000000=J,time(time_out(sleep(10),1,R)).
% 0.000 CPU in 10.000 seconds (Inf% CPU)
J = 100000000,
R = success.