From 1ebdb6a90b46c19993cae6fbea13bb48fe737722 Mon Sep 17 00:00:00 2001 From: Kevin Tew Date: Thu, 12 Aug 2010 13:26:22 -0600 Subject: [PATCH] Places: remove old code --- collects/scribblings/places/places.scrbl | 34 +++++++++++++----------- src/racket/src/places.c | 16 +++++------ 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/collects/scribblings/places/places.scrbl b/collects/scribblings/places/places.scrbl index 15a3282857..032ff72af4 100644 --- a/collects/scribblings/places/places.scrbl +++ b/collects/scribblings/places/places.scrbl @@ -14,18 +14,17 @@ @; ---------------------------------------------------------------------- -The PLT futures API enables the development of parallel programs which +The PLT Places API enables the development of parallel programs which take advantage of machines with multiple processors, cores, or hardware threads. @defmodule[racket/place]{} -@defproc[(place [module-path module-path?] [start-proc proc?] [place-channel place-channel?]) place?]{ +@defproc[(place [module-path module-path?] [start-proc proc?]) place?]{ Starts running @racket[start-proc] in parallel. @racket[start-proc] must - be a function defined in @racket[module-path]. Each place is created with a racket[place-channel] - that permits communication with the place originator. This initial channel can be overridden with - an optional @racket[place-channel] argument. The @racket[place] + be a function defined in @racket[module-path]. The @racket[place] procedure returns immediately with a place descriptor value representing the newly constructed place. + Each place descriptor value is also a racket[place-channel] that permits communication with the place. } @defproc[(place-wait [p place?]) exact-integer?]{ @@ -38,12 +37,12 @@ hardware threads. } @defproc[(place-channel) (values place-channel? place-channel?)]{ - Returns two @racket[place-channel] objects. + Returns two @racket[place-channel] endpoint objects. - One @racket[place-channel] should be used by the current @racket[place] to send + One @racket[place-channel] endpoint should be used by the current @racket[place] to send messages to a destination @racket[place]. - The other @racket[place-channel] should be sent to a destination @racket[place] over + The other @racket[place-channel] endpoint should be sent to a destination @racket[place] over an existing @racket[place-channel]. } @@ -65,15 +64,18 @@ hardware threads. Returns an immutable message received on channel @racket[ch]. } -@section[#:tag "example"]{How Do I Keep Those Cores Busy?} +@section[#:tag "example"]{Basic Example?} -This code launches two places passing 1 and 2 as the initial channels -and then waits for the places to complete and return. +This code launches two places, echos a message to them and then waits for the places to complete and return. @racketblock[ - (let ((pls (map (lambda (x) (place "place-worker.ss" 'place-main x)) - (list 1 2)))) - (map place-wait pls)) +(let ([pls (for/list ([i (in-range 2)]) + (place "place-worker.rkt" 'place-main))]) + (for ([i (in-range 2)] + [p pls]) + (place-channel-send p i) + (printf "~a~n" (place-channel-recv p))) + (map place-wait pls)) ] This is the code for the place-worker.ss module that each place will execute. @@ -82,8 +84,8 @@ This is the code for the place-worker.ss module that each place will execute. (module place-worker racket (provide place-main) - (define (place-main x) - (printf "IN PLACE ~a~n" x))) + (define (place-main ch) + (place-channel-send ch (format "Hello from place ~a" (place-channel-recv ch))))) ] @section[#:tag "place-channels"]{Place Channels} diff --git a/src/racket/src/places.c b/src/racket/src/places.c index aabaa59d97..27b206ed60 100644 --- a/src/racket/src/places.c +++ b/src/racket/src/places.c @@ -73,7 +73,7 @@ void scheme_init_place(Scheme_Env *env) plenv = scheme_primitive_module(scheme_intern_symbol("#%place"), env); - PLACE_PRIM_W_ARITY("place", scheme_place, 1, 3, plenv); + PLACE_PRIM_W_ARITY("place", scheme_place, 2, 2, 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?", scheme_place_p, 1, 1, plenv); @@ -161,29 +161,25 @@ Scheme_Object *scheme_place(int argc, Scheme_Object *args[]) { place_data = MALLOC_ONE(Place_Start_Data); place_data->ready = ready; - if (argc == 2 || argc == 3 ) { + if (argc == 2) { Scheme_Object *so; so = scheme_places_deep_copy_in_master(args[0]); place_data->module = so; so = scheme_places_deep_copy_in_master(args[1]); place_data->function = so; place_data->ready = ready; - if (argc == 2) { + + /* create channel */ + { Scheme_Place_Bi_Channel *channel; channel = scheme_place_bi_channel_create(); place->channel = (Scheme_Object *) channel; channel = scheme_place_bi_peer_channel_create(channel); place_data->channel = (Scheme_Object *) channel; } - else { - Scheme_Object *channel; - channel = args[2]; - place_data->channel = channel; - place->channel = channel; - } } else { - scheme_wrong_count_m("place", 1, 2, argc, args, 0); + scheme_wrong_count_m("place", 2, 2, argc, args, 0); } collection_paths = scheme_current_library_collection_paths(0, NULL);