Like process-wait-local, but also calls the wait function periodically.
mp
process-wait-local-with-periodic-checks wait-reason period function &rest args
wait-reason⇩ |
A string. |
period⇩ |
A positive real. |
function⇩ |
A function designator. |
args⇩ |
Arguments passed to function. |
The function process-wait-local-with-periodic-checks
suspends the current Lisp process until the wait function function applied to args returns true. It is like process-wait-local, but also calls function periodically.
After each call to function, the process sleeps at most period seconds before calling function again. If the process is poked while sleeping, it wakes up, calls function, and then (if function returns nil
), sleeps again for at most period seconds.
wait-reason is used as the wait-reason while waiting.
The resolution of the period is dependent on the underlying operating system. Many systems give time-slices of few milliseconds, so the actual period may be out by a few milliseconds. In general, periods of 0.1 seconds or more are reasonably reliable, though not exact. Shorter periods become less and less reliable.
If the period is short, the wait function is called frequently, and hence there is more overhead for the system. With a reasonable wait function and a period of 0.1 or more, this overhead is probably insignificant. If you use shorter periods, or an expensive wait function, you may want to check what the overhead is. The easiest way to check is to make sure your system is such that the wait function returns nil
, then run:
(ignore-errors ; just in case (sys:with-other-threads-disabled (time (mp:process-wait-local-with-timeout-and-periodic-checks "Timing" 5 period function args))))
When this form returns, compare the user and system times (which is what it actually used) to the elapsed time (which should be approximately 5 seconds). That will tell you what fraction of a "CPU" is used by the call. If the user and system time are less than 0.01 seconds, you may want to increase the time to get a more accurate number.
Warning: inside the scope of with-other-threads-disabled, the rest of the threads are disabled. So if your wait function ends up waiting for something that has to happen on another thread, your system will be deadlocked.
process-poke
process-wait-local
process-wait-local-with-timeout-and-periodic-checks
19.6 Process Waiting and communication between processes
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:51