【问题标题】:YAP PROLOG timeout issueYAP PROLOG 超时问题
【发布时间】:2015-11-08 18:56:09
【问题描述】:

谁能解释为什么下面的 YAP 代码不会导致变量 Resulttime_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).

根据documentation,谓词应该如下工作:

time_out(+Goal, +Timeout, -Result)

执行目标Goal 有时间限制 Timeout,其中Timeout 以毫秒为单位。如果目标 成功,将Resultsuccess 统一起来。如果计时器在 目标终止,将Resulttime_out 统一起来。

【问题讨论】:

  • 哪个版本?编译时是否支持线程?
  • 没有线程支持的 YAP 6.3.3

标签: prolog yap


【解决方案1】:

YAP 的文档还指出:

最后,即使计时器以毫秒为单位设置,当前 实现依赖于alarm/3,因此只能提供 以秒为单位的精度。

反过来,sleep/1 的文档指出:

阻塞当前线程Time秒。

但这种情况下的问题可能与时间无关,而是因为对 sleep/1 的调用阻塞了正在执行 time_out/3 调用的当前线程。尽管如此,我还是尝试了 time_out/3 谓词与其他目标,也无法获得预期的超时时间。因此,它可能存在一些错误。

【讨论】:

  • 我让 YAP 开发人员知道了这个线程。我建议您直接联系他或在 YAP 邮件列表中发帖。
【解决方案2】:

(不知怎的,我错过了这个帖子)

首先,sleep/1time_out/3 不要聚集在一起。 time_out/3 会等待一定数量的 CPU 时间或线程时间毫秒,而 sleep/1 会实时休眠几秒。与original in SICStus 相比,YAP 存在一定的局限性,请参阅手册了解更多信息。

在当前从 git 的开发版本中(最后一次提交 d5ce9a137668fe1ae34e2d47c91fc2725ae04a5f, 日期:Wed Apr 22 14:21:20 2015 -0600),机制好像坏了。

在 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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    相关资源
    最近更新 更多