Places: rename place and place/anon

This commit is contained in:
Kevin Tew 2011-06-10 11:06:29 -06:00
parent 8f6a4c5549
commit 1473b7775f
11 changed files with 28 additions and 42 deletions

View File

@ -11,7 +11,7 @@
(for-syntax racket/base (for-syntax racket/base
racket/syntax)) racket/syntax))
(provide place (provide place-dynamic
place-sleep place-sleep
place-wait place-wait
place-kill place-kill
@ -23,8 +23,7 @@
place? place?
place-channel-put/get place-channel-put/get
processor-count processor-count
place/anon place
place/thunk
define-place define-place
(rename-out [pl-place-enabled? place-enabled?])) (rename-out [pl-place-enabled? place-enabled?]))
@ -46,7 +45,7 @@
(loop))))) (loop)))))
ch)) ch))
(define (th-place mod funcname) (define (th-place-dynamic mod funcname)
(unless (or (path-string? mod) (resolved-module-path? mod)) (unless (or (path-string? mod) (resolved-module-path? mod))
(raise-type-error 'place "resolved-module-path? or path-string?" 0 mod funcname)) (raise-type-error 'place "resolved-module-path? or path-string?" 0 mod funcname))
(unless (symbol? funcname) (unless (symbol? funcname)
@ -121,7 +120,7 @@
(define-syntax-rule (define-pl x p t) (define x (if (pl-place-enabled?) p t))) (define-syntax-rule (define-pl x p t) (define x (if (pl-place-enabled?) p t)))
(define-pl place pl-place th-place) (define-pl place-dynamic pl-place-dynamic th-place-dynamic)
(define-pl place-sleep pl-place-sleep th-place-sleep) (define-pl place-sleep pl-place-sleep th-place-sleep)
(define-pl place-wait pl-place-wait th-place-wait) (define-pl place-wait pl-place-wait th-place-wait)
(define-pl place-kill pl-place-kill th-place-kill) (define-pl place-kill pl-place-kill th-place-kill)
@ -147,13 +146,13 @@
#'(let ([module-path (resolved-module-path-name #'(let ([module-path (resolved-module-path-name
(variable-reference->resolved-module-path (variable-reference->resolved-module-path
(#%variable-reference)))]) (#%variable-reference)))])
(place module-path (quote funcname))))])) (place-dynamic module-path (quote funcname))))]))
(define-syntax (place/thunk stx) (define-syntax (place/thunk stx)
(with-syntax ([create-place (gen-create-place stx)]) (with-syntax ([create-place (gen-create-place stx)])
#'(lambda () create-place))) #'(lambda () create-place)))
(define-syntax (place/anon stx) (define-syntax (place stx)
(gen-create-place stx)) (gen-create-place stx))

View File

@ -64,7 +64,7 @@ message to each, and then waits for the places to complete and return:
@racketblock[ @racketblock[
(let ([pls (for/list ([i (in-range 2)]) (let ([pls (for/list ([i (in-range 2)])
(place "place-worker.rkt" 'place-main))]) (place-dynamic "place-worker.rkt" 'place-main))])
(for ([i (in-range 2)] (for ([i (in-range 2)]
[p pls]) [p pls])
(place-channel-put p i) (place-channel-put p i)
@ -98,7 +98,7 @@ racket
@racket[#f] otherwise. @racket[#f] otherwise.
} }
@defproc[(place [module-path module-path?] [start-proc symbol?]) place?]{ @defproc[(place-dynamic [module-path module-path?] [start-proc symbol?]) place?]{
Creates a @tech{place} to run the procedure that is identified by Creates a @tech{place} to run the procedure that is identified by
@racket[module-path] and @racket[start-proc]. The result is a @racket[module-path] and @racket[start-proc]. The result is a
@ -127,25 +127,12 @@ racket
Terminates the place indicated by @racket[p], Terminates the place indicated by @racket[p],
} }
@defform[(place place-channel? body ...)]{
@defform[(place/thunk place-channel? body ...)]{
In-line definition of a place worker body, which is lifted up to module scope. In-line definition of a place worker body, which is lifted up to module scope.
@racket[place/thunk] closes over only module scope variables. @racket[place] closes over only module scope variables.
Returns a thunk for creating the described place.
}
@defform[(place/anon place-channel? body ...)]{
In-line definition of a place worker body, which is lifted up to module scope.
@racket[place/anon] closes over only module scope variables.
Returns the place descriptor for the newly constructed place. Returns the place descriptor for the newly constructed place.
} }
@defform[(define-place (place-name-id place-channel-id) body ...)]{
In-line definition of a place worker body, which is lifted up to module scope.
@racket[define-place] closes over only module scope variables.
Defines a procedure for creating the described place.
}
@defproc[(place-channel) (values place-channel? place-channel?)]{ @defproc[(place-channel) (values place-channel? place-channel?)]{
Returns two @tech{place channels}. Data sent through the first Returns two @tech{place channels}. Data sent through the first

View File

@ -116,7 +116,7 @@
(define/public (spawn _id module-path funcname [initialmsg #f]) (define/public (spawn _id module-path funcname [initialmsg #f])
(set! id _id) (set! id _id)
(set! pl (place (string->path module-path) funcname)) (set! pl (place-dynamic (string->path module-path) funcname))
(when initialmsg (send/msg (s-exp->fasl (serialize (initialmsg id)))))) (when initialmsg (send/msg (s-exp->fasl (serialize (initialmsg id))))))
(define/public (send/msg msg) (define/public (send/msg msg)
(DEBUG_COMM (eprintf "CSENDING ~v ~v\n" pl msg)) (DEBUG_COMM (eprintf "CSENDING ~v ~v\n" pl msg))

View File

@ -57,7 +57,7 @@
END END
"pct1.ss") "pct1.ss")
(let ([pl (place "pct1.ss" 'place-main)]) (let ([pl (place-dynamic "pct1.ss" 'place-main)])
(define message-size (* 4024 1024)) (define message-size (* 4024 1024))
(define four-k-message (make-bytes message-size 65)) (define four-k-message (make-bytes message-size 65))
(define count 150) (define count 150)
@ -86,7 +86,7 @@ END
END END
"pct1.ss") "pct1.ss")
(let ([pl (place "pct1.ss" 'place-main)]) (let ([pl (place-dynamic "pct1.ss" 'place-main)])
(define tree (let loop ([depth 8]) (define tree (let loop ([depth 8])
(if (depth . <= . 0) (if (depth . <= . 0)
1 1

View File

@ -48,7 +48,7 @@ END
(let ([pls (time-n msg 0 (let ([pls (time-n msg 0
(for/list ([i (in-range plcnt)]) (for/list ([i (in-range plcnt)])
(let ([p (place module-path 'place-main)]) (let ([p (place-dynamic module-path 'place-main)])
(place-channel-get p) (place-channel-get p)
p)))]) p)))])
(barrier-m pls) (barrier-m pls)
@ -57,7 +57,7 @@ END
(let ([pls (time-n msg 1 (let ([pls (time-n msg 1
(let ([pls (for/list ([i (in-range plcnt)]) (let ([pls (for/list ([i (in-range plcnt)])
(place module-path 'place-main))]) (place-dynamic module-path 'place-main))])
(map place-channel-get pls) pls))]) (map place-channel-get pls) pls))])
(barrier-m pls) (barrier-m pls)
(places-wait pls))) (places-wait pls)))

View File

@ -12,7 +12,7 @@
racket/file)) racket/file))
(provide (provide
place place-dynamic
place-wait place-wait
place-kill place-kill
place-channel-get place-channel-get
@ -45,7 +45,7 @@
(deserialize (fasl->s-exp (read (place-channel-s-in (resolve->channel ch)))))) (deserialize (fasl->s-exp (read (place-channel-s-in (resolve->channel ch))))))
;; create a place given a module file path and a func-name to invoke ;; create a place given a module file path and a func-name to invoke
(define (place module-name func-name) (define (place-dynamic module-name func-name)
(define (send/msg x ch) (define (send/msg x ch)
(write x ch) (write x ch)
(flush-output ch)) (flush-output ch))
@ -133,7 +133,7 @@
(splat (syntax->datum worker-syntax) module-path) (splat (syntax->datum worker-syntax) module-path)
(define place-syntax #`(place #,module-path (quote name))) (define place-syntax #`(place-dynamic #,module-path (quote name)))
;(write (syntax->datum place-syntax)) ;(write (syntax->datum place-syntax))
place-syntax)])) place-syntax)]))
@ -144,7 +144,7 @@
(define (place/current-module-path funcname) (define (place/current-module-path funcname)
(with-syntax ([funcname funcname]) (with-syntax ([funcname funcname])
#'(let ([module-path (resolved-module-path-name (variable-reference->resolved-module-path (#%variable-reference)))]) #'(let ([module-path (resolved-module-path-name (variable-reference->resolved-module-path (#%variable-reference)))])
(place module-path (quote funcname))))) (place-dynamic module-path (quote funcname)))))
(with-syntax ([interal-def-name (syntax-local-lift-expression #'(lambda () ((lambda (args ...) body ...) (place-child-channel))))]) (with-syntax ([interal-def-name (syntax-local-lift-expression #'(lambda () ((lambda (args ...) body ...) (place-child-channel))))])
(syntax-local-lift-provide #'(rename interal-def-name name))) (syntax-local-lift-provide #'(rename interal-def-name name)))
(place/current-module-path #'name))])) (place/current-module-path #'name))]))

View File

@ -56,7 +56,7 @@
(splat (syntax->datum worker-syntax) module-path-str) (splat (syntax->datum worker-syntax) module-path-str)
(define place-syntax #`(place #,module-path (quote name))) (define place-syntax #`(place-dynamic #,module-path (quote name)))
;(write (syntax->datum place-syntax)) (newline) ;(write (syntax->datum place-syntax)) (newline)
place-syntax)])) place-syntax)]))

View File

@ -33,7 +33,7 @@ END
[(vector) (values (processor-count) 10 1000000)] [(vector) (values (processor-count) 10 1000000)]
[(vector a b c) (values a b c)])) [(vector a b c) (values a b c)]))
(define pls (for/list ([i (in-range plcnt)]) (place "pct1.ss" 'place-main))) (define pls (for/list ([i (in-range plcnt)]) (place-dynamic "pct1.ss" 'place-main)))
(for ([i (in-range plcnt)] (for ([i (in-range plcnt)]
[pl pls]) [pl pls])
@ -70,7 +70,7 @@ END
(for ([j (in-range reps)]) (for ([j (in-range reps)])
(time-n "require-algol-parse/racket-class" j (time-n "require-algol-parse/racket-class" j
(define pls (for/list ([i (in-range plcnt)]) (place "pct2.ss" 'place-main))) (define pls (for/list ([i (in-range plcnt)]) (place-dynamic "pct2.ss" 'place-main)))
(barrier-m pls)))) (barrier-m pls))))
(symbol-test) (symbol-test)

View File

@ -143,7 +143,7 @@
(define ll (length l)) (define ll (length l))
(printf "Master ~a length ~a\n" desc ll) (printf "Master ~a length ~a\n" desc ll)
(define p (place/anon ch (define p (place ch
(define l (place-channel-get ch)) (define l (place-channel-get ch))
(define wl (length l)) (define wl (length l))
(printf "Worker length ~a\n" wl) (printf "Worker length ~a\n" wl)
@ -222,7 +222,7 @@
(place-wait pl)) (place-wait pl))
(let ([p (place/anon ch (let ([p (place ch
(with-handlers ([exn:break? (lambda (x) (place-channel-put ch "OK"))]) (with-handlers ([exn:break? (lambda (x) (place-channel-put ch "OK"))])
(place-channel-put ch "ALIVE") (place-channel-put ch "ALIVE")
(sync never-evt) (sync never-evt)

View File

@ -26,9 +26,9 @@
(arity-test place-channel-put/get 2 2) (arity-test place-channel-put/get 2 2)
(arity-test processor-count 0 0) (arity-test processor-count 0 0)
(err/rt-test (place "foo.rkt")) (err/rt-test (place-dynamic "foo.rkt"))
(err/rt-test (place null 10)) (err/rt-test (place-dynamic null 10))
(err/rt-test (place "foo.rkt" 10)) (err/rt-test (place-dynamic "foo.rkt" 10))
(let ([p (place/base (p1 ch) (let ([p (place/base (p1 ch)
(printf "Hello form place 2\n") (printf "Hello form place 2\n")

View File

@ -89,7 +89,7 @@ void scheme_init_place(Scheme_Env *env)
GLOBAL_PRIM_W_ARITY("place-enabled?", scheme_place_enabled, 0, 0, plenv); GLOBAL_PRIM_W_ARITY("place-enabled?", scheme_place_enabled, 0, 0, plenv);
GLOBAL_PRIM_W_ARITY("place-shared?", scheme_place_shared, 1, 1, plenv); GLOBAL_PRIM_W_ARITY("place-shared?", scheme_place_shared, 1, 1, plenv);
PLACE_PRIM_W_ARITY("place", scheme_place, 2, 2, plenv); PLACE_PRIM_W_ARITY("place-dynamic", scheme_place, 2, 2, plenv);
PLACE_PRIM_W_ARITY("place-sleep", scheme_place_sleep, 1, 1, plenv); PLACE_PRIM_W_ARITY("place-sleep", scheme_place_sleep, 1, 1, plenv);
PLACE_PRIM_W_ARITY("place-wait", scheme_place_wait, 1, 1, plenv); PLACE_PRIM_W_ARITY("place-wait", scheme_place_wait, 1, 1, plenv);
PLACE_PRIM_W_ARITY("place-kill", scheme_place_kill, 1, 1, plenv); PLACE_PRIM_W_ARITY("place-kill", scheme_place_kill, 1, 1, plenv);