[M3devel] AlertPause(0) is alertable?

Jay K jay.krell at cornell.edu
Sun Dec 13 06:38:46 CET 2009


The 4.1 code has the bug (this is probably identical but I haven't done a mechanical diff,

but it is plain to see it has the bug):

(I bought 4.1 too).

 


PROCEDURE AlertPause(n: LONGREAL) RAISES {Alerted} =
  VAR amount, thisTime: LONGREAL;
  CONST Limit = FLOAT(LAST(CARDINAL), LONGREAL) / 1000.0D0 - 1.0D0;
  VAR self: T;
  BEGIN
    self := Self();
    amount := n;
    WHILE amount > 0.0D0 DO
      thisTime := MIN (Limit, amount);
      amount := amount - thisTime;
      WinBase.EnterCriticalSection(cm);
      InnerTestAlert(self);
      self.alertable := TRUE;
      <* ASSERT(self.waitingOn = NIL) *>
      WinBase.LeaveCriticalSection(cm);
      EVAL WinBase.WaitForSingleObject(self.waitSema, ROUND(thisTime*1000.0D0));
      WinBase.EnterCriticalSection(cm);
      self.alertable := FALSE;
      IF self.alerted THEN
        (* Sadly, the alert might have happened after we timed out on the
           semaphore and before we entered "cm". In that case, we need to
           decrement the semaphore's count *)
        EVAL WinBase.WaitForSingleObject(self.waitSema, 0);
        InnerTestAlert(self);
      END;
      WinBase.LeaveCriticalSection(cm);
    END;
  END AlertPause;


 - Jay



 


Date: Sun, 13 Dec 2009 00:16:31 -0500
From: rcoleburn at scires.com
To: m3devel at elegosoft.com
Subject: Re: [M3devel] AlertPause(0) is alertable?




Jay:  I never messed around much with the 3.6 code.  I purchased the 4.1 commercial version.  Prior to that we did use the DEC SRC version and that would have been the extent of my 3.6 familiarity.  After the commercial release came out, we went exclusively with Critical Mass 4.1.
Regards,
Randy

>>> Jay K <jay.krell at cornell.edu> 12/12/2009 11:56 PM >>>
Randy, Thanks. I fixed Win32 to be like that. pthreads still looks wrong.
 
 
Note that the 3.6 code doesn't seem to get it right:
 
 
PROCEDURE AlertPause(n: LONGREAL) RAISES {Alerted} =
  VAR amount, thisTime: LONGREAL;
  CONST Limit = FLOAT(LAST(CARDINAL), LONGREAL) / 1000.0D0 - 1.0D0;
  VAR self: T;
  BEGIN
    self := Self();
    amount := n;
    WHILE amount > 0.0D0 DO
      thisTime := MIN (Limit, amount);
      amount := amount - thisTime;
      WinBase.EnterCriticalSection(cm);
      InnerTestAlert(self);
      self.alertable := TRUE;
      <* ASSERT(self.waitingOn = NIL) *>
      WinBase.LeaveCriticalSection(cm);
      EVAL WinBase.WaitForSingleObject(self.waitSema, ROUND(thisTime*1.0D3));
      WinBase.EnterCriticalSection(cm);
      self.alertable := FALSE;
      IF self.alerted THEN
        (* Sadly, the alert might have happened after we timed out on the
           semaphore and before we entered "cm". In that case, we need to
           decrement the semaphore's count *)
        EVAL WinBase.WaitForSingleObject(self.waitSema, 0);
        InnerTestAlert(self);
      END;
      WinBase.LeaveCriticalSection(cm);
    END;
  END AlertPause;

The 3.6 and current user threads code seems ok, but I've not very familiar with it.
 
This might be one of those things though that's been consistently broken for so long that it's best not to depend on?
Prefer AlertPause(0.01) over AlertPause(0)??
 
 
 - Jay


 




Date: Sat, 12 Dec 2009 23:56:08 -0500
From: rcoleburn at scires.com
To: m3devel at elegosoft.com
Subject: Re: [M3devel] AlertPause(0) is alertable?




My understanding of the interface has always been as you suggest, namely, yes you should get an "Alerted" exception if the thread is marked alerted regardless of the value of the n (seconds) parameter.
 
Regards,
Randy

>>> Jay K <jay.krell at cornell.edu> 12/12/2009 7:37 PM >>>
If I call AlertPause with <= 0 time, should I recieve alerts?
Current pthread/win32 implementations: no.
 They say if time <= then return end before doing much.
My suspicion: yes.


Thread.i3:
 
PROCEDURE AlertPause(n: LONGREAL) RAISES {Alerted};
(* Like "Pause", but if the thread is marked alerted at the time of
   the call or sometime during the wait, raise "Alerted". *)

 
 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20091213/9d92f0c5/attachment-0002.html>


More information about the M3devel mailing list