Hi David,

On Mon, Mar 6, 2017 at 5:50 PM, David T. Lewis <lewis@mail.msen.com> wrote:

In the VM, the millisecond clock wraps within the 32 bit integer range:

  #define MillisecondClockMask 0x1FFFFFFF

In the Cuis image, Delay class>>handleTimerEvent does this:

  nextTick := nextTick min: SmallInteger maxVal.

On a 64-bit Spur image, SmallInteger maxVal is 16rFFFFFFFFFFFFFFF, but on
a 32-bit image it is 16r3FFFFFFF.

Could that be it?

I don't really know how to test in Squeak. As you say, Squeak is now
using the microsecond clock in #handleTimerEvent. I do not see anything
in primitiveSignalAtMilliseconds that would behave any differently on
a 64 bit versus 32 bit image or VM, but I do not know how to test to
be sure.

I bet that the following code from primitiveSignalAtMilliseconds ends up wrapping when given
    Delay primSignal: s atMilliseconds: Time primMillisecondClock - 10.

deltaMsecs := msecs - (self ioMSecs bitAnd: MillisecondClockMask).
deltaMsecs < 0 ifTrue:
[deltaMsecs := deltaMsecs + MillisecondClockMask + 1].
nextWakeupUsecs := self ioUTCMicroseconds + (deltaMsecs * 1000).

and I bet you'll find that the VM will wake up in about 6 days and 5 hours ;-)


I suppose we could fix this, but I'm *much* happier to simply not use primitiveSignalAtMilliseconds and stay with the simpler and wrapping-immune primitiveSignalAtUTCMicroseconds


Dave


On Mon, Mar 06, 2017 at 11:06:22AM -0300, Juan Vuletich wrote:
>
> I finally understood what was happening. The problem with is primitive 136:
>
> primSignal: aSemaphore atMilliseconds: aSmallInteger
>     "Signal the semaphore when the millisecond clock reaches the value
> of the second argument. Fail if the first argument is neither a
> Semaphore nor nil. Essential. See Object documentation whatIsAPrimitive."
> <primitive: 136>
>     ^self primitiveFailed
>
> If the requested tick is already in the past, all the VMs except for
> Spur-64 will signal the semaphore anyway. Spur-64 won't. Taking care of
> this in the Cuis image was easy enough.
>
> Squeak seems not to be affected because it uses a newer primitive, that
> takes the large integer microsecond ticker, that might have the older
> behavior (signaling anyway). I'm not really sure, and maybe someone
> could check the primitive behavior and the corresponding assumptions in
> Squeak.
>
> Older Squeak images are not affected, as they are all 32-bit. So maybe
> there's no action required. In any case, making the behavior consistent
> across VMs and in both primitives would be nice.
>
> Cheers,
>
> On 3/3/2017 3:55 PM, Juan Vuletich wrote:
> >
> >
> >
> >Hi Folks,
> >
> >Today, I was able to get closer to the origin of the problem. The
> >problem is when Morphic tries to do a Delay (inter-cycle-pause) of 1
> >or two milliseconds. (Usually they are quite larger, and the problem
> >does not appear). With the 64-bit VM, sometimes very short delays hang
> >the complete system. I don't know why, but this:
> >
> >waitDelay _ Delay forMilliseconds: 50.
> >[ true ] whileTrue: [
> >    1000 atRandom print.
> >    waitDelay setDelay: 1; wait ].
> >
> >is enough to hang Cuis in a short time. When trying to reproduce the
> >problem in Squeak I had mixed results. It doesn't seem to hang there,
> >but if I let this run for a couple of minutes and then try to halt
> >with alt-. , then the hang occurs, and Squeak becomes irresponsibe. As
> >a workaround, in Cuis in the inter cycle pause, I'm avoiding very
> >short delays.
> >
> >I'm not sure if the bug is in the VM, in  the image, or both, but it
> >is still there, and it also affects Squeak. I haven't tried it, but
> >Pharo might also have the problem (if not, it can show a possible
> >solution).
> >
> >BTW, Bert, I guess Squeak never does short delays in #interCyclePause: ...
> >
> >Thanks,
> >
> >On 2/6/2017 12:28 PM, Bert Freudenberg wrote:
> >>
> >>
> >>
> >>Yes, I tried with Spur64. Have not seen it freeze yet on Mac in
> >>Squeak, but we possibly have not replicated the test well enough yet.
> >>
> >>It *did* freeze in Cuis Spur64 on Mac too.
> >>
> >>- Bert -
> >>
> >>On Mon, Feb 6, 2017 at 2:08 PM, Juan Vuletich <juanvuletich@zoho.com
> >><mailto:juanvuletich@zoho.com>> wrote:
> >>
> >>
> >>    Were you usig Spur64? On Debian it does not freeze with CogV3 or
> >>    Spur32. Only with Spur64.
> >>
> >>    Thanks,
> >>    Juan
> >>
> >>    Sent using Zoho Mail <https://www.zoho.com/mail/>
> >>
> >>
> >>        ---- On Mon, 06 Feb 2017 09:19:48 -0300 *bert@freudenbergs.de
> >>        <mailto:bert@freudenbergs.de> * wrote ----
> >>
> >>        On Mon, Feb 6, 2017 at 3:15 AM, David T. Lewis
> >>        <lewis@mail.msen.com <mailto:lewis@mail.msen.com>> wrote:
> >>
> >>            It would be interesting to try reproducing this in a
> >>            Squeak image, but I
> >>            have not quite figured out how to make the Tokenish
> >>            example work in Squeak.
> >>
> >>
> >>        See attachment. Did not freeze on Mac with 10 Tokenish jumping.
> >>        - Bert -
> >>
> >>
> >>
> >
> >
> >--
> >Juan Vuletich
> >www.cuis-smalltalk.org
> >https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
> >@JuanVuletich
>
>
> --
> Juan Vuletich
> www.cuis-smalltalk.org
> https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
> @JuanVuletich
>




--
_,,,^..^,,,_
best, Eliot