[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preemption, Persistence, and Mobility



Hello all:

I concur with Mathias.  If you google
Using Continuations to Implement Thread Management and Communication in Operating Systems - Draves, Bershad, Rashid, Dean (ResearchIndex)
one page that came up is apparently a forward and backward citation index.
 
Steve

>>> Matthias Felleisen <matthias@ccs.neu.edu> 04/23/02 03:33PM >>> 

If you have continuations in your language, you can fake threads easily. 
See the PLt Scheme code below. Now you can experiment with your thread 
interface. 

If you would like to read up on engines, look for the papers by Bob Hieb 
and Kent Dybvig and references in there. 

If you would like to study the use of continuations in an OS so that you 
lift it back to a LL language, read Rich Draves thesis on the Mach 4 
kernel, and the use of continuations in it. 

-- Matthias 

(module threads mzscheme 
; a simple thread package from call/cc 

(provide start-thread-system ; (-> Void) -> Void 
; supply a thunk to start up the thread system (main) 

create-thread ; (-> Void) -> Void 
; creates and enqueues a thread 

suspend-thread ; (-> Void) 
; suspend current thread, enqueue the suspension, run next in queue 
) 

(require queue) 

(define (start-thread-system th) 
(call/cc 
(lambda (s) 
(set! stop (lambda () (s (void)))) 
(create-thread th) 
(dispatch)))) 

(define (create-thread th) 
(enq (lambda () (th) (dispatch) (stop)))) 

(define (suspend-thread) 
(call/cc 
(lambda (k) 
(enq (lambda () (k (void)))) 
(dispatch)))) 

; --------------------------------------------------------------------------- 
; auxiliary state and functions 

; -> Void 
; run the next thread on queue, if available 
(define (dispatch) 
(unless (empty?) (((deq))))) 

; stop : continuation 
; the continuation of the starter thread 
(define stop void)) 

a tester: 

(module example mzscheme 
(require threads) 

(define (looping x i) 
(letrec ([loop 
(lambda (i) 
(printf "in ~s[~s]~n" x i) 
(suspend-thread) 
(unless (= i 0) 
(loop (- i 1))))]) 
(lambda () (loop i)))) 

(start-thread-system 
(lambda () 
(create-thread (looping 'a 2)) 
(create-thread (looping 'b 4))))) 

the cheap queue module: 
(module queue mzscheme 
; a "cheap" queue implementation 
(provide enq deq empty?) 
(define the-Q '()) 
(define (empty?) (null? the-Q)) 
(define (enq x) (set! the-Q (append! the-Q (list x)))) 
(define (deq) (begin0 (car the-Q) (set! the-Q (cdr the-Q))))) 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR></HEAD>
<BODY style="FONT: 8pt Tahoma; MARGIN-LEFT: 2px; MARGIN-TOP: 2px">
<DIV>Hello all:</DIV>
<DIV>&nbsp;</DIV>
<DIV>I concur with Mathias.&nbsp; If you google</DIV>
<DIV>Using Continuations to Implement Thread Management and Communication in 
Operating Systems - Draves, Bershad, Rashid, Dean (ResearchIndex)</DIV>
<DIV>one page that came up is apparently a forward and backward citation 
index.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Steve</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt;&gt;&gt; Matthias Felleisen &lt;matthias@ccs.neu.edu&gt; 04/23/02 
03:33PM &gt;&gt;&gt; <BR><BR>If you have continuations in your language, you can 
fake threads easily. <BR>See the PLt Scheme code below. Now you can experiment 
with your thread <BR>interface. <BR><BR>If you would like to read up on engines, 
look for the papers by Bob Hieb <BR>and Kent Dybvig and references in there. 
<BR><BR>If you would like to study the use of continuations in an OS so that you 
<BR>lift it back to a LL language, read Rich Draves thesis on the Mach 4 
<BR>kernel, and the use of continuations in it. <BR><BR>-- Matthias 
<BR><BR>(module threads mzscheme <BR>; a simple thread package from call/cc 
<BR><BR>(provide start-thread-system ; (-&gt; Void) -&gt; Void <BR>; supply a 
thunk to start up the thread system (main) <BR><BR>create-thread ; (-&gt; Void) 
-&gt; Void <BR>; creates and enqueues a thread <BR><BR>suspend-thread ; (-&gt; 
Void) <BR>; suspend current thread, enqueue the suspension, run next in queue 
<BR>) <BR><BR>(require queue) <BR><BR>(define (start-thread-system th) 
<BR>(call/cc <BR>(lambda (s) <BR>(set! stop (lambda () (s (void)))) 
<BR>(create-thread th) <BR>(dispatch)))) <BR><BR>(define (create-thread th) 
<BR>(enq (lambda () (th) (dispatch) (stop)))) <BR><BR>(define (suspend-thread) 
<BR>(call/cc <BR>(lambda (k) <BR>(enq (lambda () (k (void)))) <BR>(dispatch)))) 
<BR><BR>; 
--------------------------------------------------------------------------- 
<BR>; auxiliary state and functions <BR><BR>; -&gt; Void <BR>; run the next 
thread on queue, if available <BR>(define (dispatch) <BR>(unless (empty?) 
(((deq))))) <BR><BR>; stop : continuation <BR>; the continuation of the starter 
thread <BR>(define stop void)) <BR><BR>a tester: <BR><BR>(module example 
mzscheme <BR>(require threads) <BR><BR>(define (looping x i) <BR>(letrec ([loop 
<BR>(lambda (i) <BR>(printf "in ~s[~s]~n" x i) <BR>(suspend-thread) <BR>(unless 
(= i 0) <BR>(loop (- i 1))))]) <BR>(lambda () (loop i)))) 
<BR><BR>(start-thread-system <BR>(lambda () <BR>(create-thread (looping 'a 2)) 
<BR>(create-thread (looping 'b 4))))) <BR><BR>the cheap queue module: 
<BR>(module queue mzscheme <BR>; a "cheap" queue implementation <BR>(provide enq 
deq empty?) <BR>(define the-Q '()) <BR>(define (empty?) (null? the-Q)) 
<BR>(define (enq x) (set! the-Q (append! the-Q (list x)))) <BR>(define (deq) 
(begin0 (car the-Q) (set! the-Q (cdr the-Q))))) <BR></DIV></BODY></HTML>