Like process-wait-local, but also calls the wait function periodically.
The function
process-wait-local-with-periodic-checks
is like process-wait-local, but also calls the wait function periodically.
After each call to the function
wait-function
, the process sleeps at most
period
seconds, and then checks the wait function. If the process is poked while sleeping, it wakes up, checks the wait function, and then (if the wait function returns
nil
), sleeps again for at most
period
seconds.
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.
LispWorks User Guide and Reference Manual - 21 Dec 2011