Differences between AbtTimedWait and Delay

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

Differences between AbtTimedWait and Delay

Postby cknittel » Mon Apr 27, 2009 4:37 am

Hi,

To wait for a number of seconds (say 5), I could use

Code: Select all
(Delay forSeconds: 5) wait.

or

Code: Select all
AbtTimedWait forSeconds: 5.

The effect seems to be the same, but the implementation of the wait differs. The Delay class uses a timer interrupt (primitive #installTimerReceiver:selector:), whereas AbtTimedWait seems to call

Code: Select all
useThreadMethod

   Sleep coroutineCallWith: waitInterval

("Sleep" being the Windows API function "<c: void 'kernel32.dll':Sleep uint32>").

The latter method seems a bit strange to me. :wink: Could you please comment on the reasoning behind the two implementations?

Thanks and best regards,
Christoph
cknittel
 
Posts: 27
Joined: Tue Nov 28, 2006 6:10 am
Location: Vienna - Austria

Re: Differences between AbtTimedWait and Delay

Postby a3aan » Mon Apr 27, 2009 5:43 am

I don't know about the reasoning but the first just delays a single process in your image while the other processes are unaffected, and the other one seems to put the whole image to sleep. Different use cases, different implementations.

HTH,
Adriaan.
Adriaan van Os
a3aan
[|]
 
Posts: 45
Joined: Fri May 25, 2007 1:41 am

Re: Differences between AbtTimedWait and Delay

Postby cknittel » Tue Apr 28, 2009 1:57 am

No, the AbtTimedWait does not put the whole image to sleep (#callWith: would do so, but #coroutineCallWith: does not).

Just try

Code: Select all
[ AbtTimedWait forSeconds: 10 ] fork

to see.

Regards,
Christoph
cknittel
 
Posts: 27
Joined: Tue Nov 28, 2006 6:10 am
Location: Vienna - Austria

Re: Differences between AbtTimedWait and Delay

Postby marten » Tue Apr 28, 2009 2:46 am

Reading the source code may give a hint ....

Code: Select all
wait
   "Block the current process for the duration of waitInterval.  Try
    to use threading to minimize overhead."

   self waitInterval == 0 ifFalse: [
      AbtThreadManager threadsSupported
         ifTrue: [self useThreadMethod]
         ifFalse: [self useRawSmalltalkMethod]]
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Differences between AbtTimedWait and Delay

Postby cknittel » Tue Apr 28, 2009 4:14 am

Hi Marten,

Yes, I saw that, but it just added to my confusion. :wink:

On Windows, AbtThreadManager threadsSupported is true, so the "thread method" (#coroutineCallWith:) is used. I am not sure if that minimizes overhead, but at least it seems to increase precision.

I just ran

Code: Select all
Time millisecondsToRun: [ (Delay forMilliseconds: 30) wait ].

Time millisecondsToRun: [ (AbtTimedWait forMilliseconds: 30) ].

and the former seems to actually run between 47 and 110 milliseconds on my system, the latter always 31-32.

So it would seem that AbtTimedWait should be used if precision is required, especially for short waits. Are there any drawbacks of using AbtTimedWait?

Regards,
Christoph
cknittel
 
Posts: 27
Joined: Tue Nov 28, 2006 6:10 am
Location: Vienna - Austria

Re: Differences between AbtTimedWait and Delay

Postby marten » Tue Apr 28, 2009 6:19 am

Consider a large software system where you work with Delays - just to simulate the time and now think about having hundreds of threads in Smalltalk (which is ok) working with AbtTimedWait. Each one would then need an external thread - which becomes very cost intensive on all operating systems. Then the Delay structure would be much better.

I therefore think, that minimizing overhead is a "relative" statement. It minimizes the overhead because Smalltalk does not have to check the end of the delay regularly.

Another thing one could ask, how do both solutions react to time changes during their delaying time ...

Marten
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: Differences between AbtTimedWait and Delay

Postby wembley » Fri May 01, 2009 6:34 am

You are correct -- AbtTimedWait was originally implemented to provide a more accurate timing mechanism than Delay. Remember Delay is driven off an interrupt which fires every 100ms (by default). This means that a delay interval can be off by that much. AbtTimedWait was created at a time when threading was not available on all platforms, thus the test for threadsSupported. The comment regarding 'minimizing overhead' relates to the difference between the threaded and non-threaded version of AbtTimedWait, not between AbtTimedWait and Delay.
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC

Re: Differences between AbtTimedWait and Delay

Postby cknittel » Thu May 07, 2009 11:08 pm

Thanks for the clarification!

Regards,
Christoph
cknittel
 
Posts: 27
Joined: Tue Nov 28, 2006 6:10 am
Location: Vienna - Austria


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest