[plt-scheme] Creating a suspended thread

From: Marc Feeley (feeley at iro.umontreal.ca)
Date: Tue Apr 14 00:18:56 EDT 2009

On 14-Apr-09, at 12:01 AM, Eli Barzilay wrote:

>>
>> The "thread/suspend" procedure submitted by Matthew runs about 5%
>> slower than the "thread" procedure alone (on MzScheme v4.1 + Intel
>> Mac OS X).  So the additional semaphore operations don't seem to add
>> much of an overhead.  But that is because thread creation in
>> MzScheme is slow in comparison to the semaphore operations (about 45
>> microseconds per thread creation + termination).  In a system with
>> faster thread creation operations the overhead becomes quite
>> noticeable (Gambit is about 45 times faster, i.e. one microsecond
>> per thread creation + termination).
>
> I'm getting different numbers: I get thread creation and termination
> at about 10 microseconds -- and that's for both versions; the
> difference is in the noise.
>
> (For these two lines:
>
>  (time (for ([i (in-range 100000)]) (kill-thread (thread void))))
>  (time (for ([i (in-range 100000)]) (kill-thread (thread/suspended  
> void))))
>
> I'm getting these medians out of 13 runs of each:
>
>  first:  cpu time: 1057 real time: 1057 gc time: 123
>  second: cpu time: 1035 real time: 1036 gc time: 148
>
> )

Eli, it appears that your machine is twice as fast as mine.  Moreover  
it is "normal termination" that I was measuring in my test, i.e.

(time (for ([i (in-range 100000)]) (thread-wait (thread void))))

which is about half as fast as with kill-thread (I guess because kill- 
thread manages to kill most of the threads before they are even  
running, thus avoiding the context switch).  So MzScheme's thread  
operations are still roughly 40 times slower than Gambit's.

Aside: don't you find it strange that in your test using "thread/ 
suspend" is *faster* than using "thread" even though "thread/suspend"  
calls "thread" and does a bunch of other operations?  That's probably  
worth some investigation.

Marc



Posted on the users mailing list.