gpt4 book ai didi

prolog - YAP PROLOG 超时问题

转载 作者:行者123 更新时间:2023-12-04 05:48:15 25 4
gpt4 key购买 nike

谁能解释为什么下面的 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)

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.

最佳答案

YAP 的文档还指出:

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.

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

Block the current thread for Time seconds.

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

关于prolog - YAP PROLOG 超时问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32966383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com