(不知怎的,我錯過了這個線程)
首先,sleep/1
和time_out/3
不要扎堆。 time_out/3
等待一定數量的毫秒CPU時間或線程時間,而sleep/1
睡眠實時秒。 YAP與original in SICStus相比有一定的侷限性,請參閱手冊瞭解更多信息。
在git的當前開發版本中(last commit d5ce9a137668fe1ae34e2d47c91fc2725ae04a5f, Date:Wed Apr 22 14:21:20 2015-06600),該機制似乎被打破。
在舊版本的6.3.4,我得到:
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.
哪個版本?編譯是否支持線程? –
YAP 6.3.3沒有線程支持 – S0rin