Did you know ... Search Documentation:
Pack resbound -- prolog/resource_bounds.pl
PublicShow source

This library allows running a goal, providing limits for the wall time, CPU time and stack usage.

See also
- call_with_time_limit/2
- call_with_depth_limit/3
 resource_bounded_call(:Goal, +MaxCPU, -Status, +Options) is det
Run Goal in a guarded environment, limiting its resources. Note that resource_bounded_call/4 does not guard against mallicious behaviour of Goal!

If all solutions of Goal are needed, Goal must be wrapped in findall/3.

Below are some examples

?- resource_bounded_call(true, 1, Status, []).
Status = true.
?- resource_bounded_call(fail, 1, Status, []).
Status = false.
?- resource_bounded_call((repeat, fail), 0.001, Status, []).
Status = timeout(cpu).
?- resource_bounded_call(sleep(20), 0.001, Status, [wall_time(1)]).
Status = timeout(wall).
?- resource_bounded_call(numlist(1, 1000000, L), 1, Status, [global(1000)]).
Status = stack_overflow(global).
Arguments:
Goal- is the goal to execute
MaxCPU- is the maximum CPU time to use
Status- is unified with the status. It is either one of the values returned by thread_join/2 or one of
timeout(cpu)
Goal was aborted due to exceeded CPU Time
timeout(wall)
Goal was aborted due to exceeded Wall Time
stack_overflow(global)
Goal terminated due to a global stack overflow
stack_overflow(local)
Goal terminated due to a local stack overflow
Options- processed
local(+KCells)
Max local stack usage in cells. Note that the actual stack limits are rounded up to the nearest power of two.
global(+KCells)
Max global stack usage in cells. The value is rounded as local(KCells).
wall_time(Time)
In limit the wall time in addition to the CPU time.