[armedbear-devel] CL:SLEEP fixed for sub-millisecond intervals

James M. Lawrence llmjjmll at gmail.com
Mon Mar 24 18:55:26 UTC 2014


On Fri, Mar 21, 2014 at 4:04 AM, Mark Evenson <evenson at panix.com> wrote:
> On 3/20/14, 23:59, James M. Lawrence wrote:
>> Hi,
>>
>> The original bug appears to still be there. For example this will hang:
>>
>> (defun test ()
>>   (let ((object (cons nil nil)))
>>     (threads:synchronized-on object
>>       (threads:object-wait object 0.000000001))))
>>
>> 1.4.0-dev-svn-14653
>> Java_HotSpot(TM)_Server_VM-Oracle_Corporation-1.7.0_04-b20
>> i386-Linux-3.2.0-24-generic-pae
>
> Sigh.  Yes, this is still not resolved with THREADS:OBJECT-WAIT in
> abcl-1.4.0-dev, although CL:SLEEP is fixed.
>
> Apparently my thinking on this was incomplete.  For the SLEEP, degrading
> to thread yield make sense for intervals less than a nanosecond.  For
> OBJECT-WAIT is it really the case that you wish to degrade to a thread
> yield without ever having tried to wait for a notification on the
> synchronized object?

In pthreads, no matter what timeout is given to
pthread_cond_timedwait, it will always release and reacquire the
mutex. A certain-to-expire timeout just means we are operating within
the Planck time of the system.

Because pthread_cond_timedwait can return spuriously, the information
it provides is not particularly useful on its own. We must always
check to see if "something happened", for instance whether data
produced by another thread has arrived. It may have arrived even if
pthread_cond_timedwait returned ETIMEDOUT.

>From what I understand of java.lang.Object.wait, the model is similar.
The main difference seems to be the weirdo interpretation of 0 =
infinity. It's discontinuous: passing 0.00000001 yields a totally
different animal than passing 0. I should be able to wait one system
Planck time unit (i.e. wait 0, without 0 meaning infinity), but I
can't.

I need to add a workaround to the ABCL implementation of
bordeaux-threads:condition-wait. If the user passes a timeout of zero
then the this should translate to TIMED-WAIT of
LEAST-POSITIVE-SINGLE-FLOAT.

On your end, I think you just need to avoid rounding a non-zero value
to zero. If the reader rounds a literal to zero then there's nothing
you can do, but 0.000000001 is well before that problem. The
separation of the reader phase in Lisp does not mix well with the
extreme discontinuity between 0 and non-zero values with TIMED-WAIT.

Best,
lmj



More information about the armedbear-devel mailing list