[plt-scheme] Parallel execution

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Sat Jan 14 18:48:30 EST 2006

On Jan 14, 2006, at 3:32 PM, Joe Marshall wrote:

> I don't think there is special interaction.  I think the threads just
> get scheduled at coarse intervals.  Probably none of the threads get
> scheduled before the BEGIN block finishes just because the BEGIN block
> finishes so quickly.

Okay, so these really are threads, then? I wondered if the OS would  
be oblivious to the existence of these threads with evaluation being  
handled by the Scheme implementation, or whether there would be  
multiple threads (at the system level), each evaluating it's own thunk?
>
> The threads are run `round robin', but rather than switching at each
> reduction, they are switched at timed intervals.  The timing is pretty
> coarse (probably no faster than dozens of times a second).

Here's another little test

(begin
   (thread
    (lambda ()
      (let loop ((i 0))
        (if (< i 10)
            (begin
              (display "A")
              (loop (+ i 1)))))))
   (thread
    (lambda ()
      (let loop ((i 0))
        (if (< i 10)
            (begin
              (display "B")
              (loop (+ i 1))))))))


Typical output is


AABBBBB#<thread:10:3>
BBAAAABBBAAAA
 >

It appears to me that each thread is getting a fair chance, but there  
do seem to be several output characters between each context switch.

===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net

"Without the requirement of mathematical aesthetics a great many  
discoveries would not have been made."
-- Albert Einstein






Posted on the users mailing list.