[plt-scheme] Parallel execution

From: Chongkai Zhu (u0476504 at utah.edu)
Date: Sat Jan 14 19:12:25 EST 2006

======= At 2006-01-14, 16:48:30 Gregory Woodhouse wrote: =======

>
>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?

PLT thread are user thread instead of kernal thread. Here is a quoting:

1 Kernel threads:
¨C OS is aware of ¡°thread¡± abstraction
¨C Each thread has separate OS state (ready, blocked,¡­)
¨C Kernel schedules threads rather than processes
¨C Kernel context switches between threads (and processes)
	= Thread switch: save/restore registers (inc. PC and SP)
	= Process switch: above plus MMU/TLB state
	= Thread switches cheaper than process (~10us vs ~30us)
2 User threads:
¨C OS is unaware of ¡°thread abstraction¡±
¨C User-level thread library implements abstraction
¨C Thread ¡°context switch¡± performed entirely within user space
¨C Requires cooperation between threads to ensure fairness

>
>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
>
>
>
>
>_________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.