[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: self for Jocaml location
Hi,
Jprims.self_location should be what you need. It returns the location
where the current thread is running. Since the type is not exactly the
correct one (location_stub vs location, which is the same thing
actually), I added a Join.self_location () function of type unit ->
Join.location. It is in cvs.
With it you can write things like:
let loc_list = ref []
let find a =
let rec find_rec = function
| [] -> raise Not_found
| (l,n) :: l' ->
if a == l then n else find_rec l'
in
find_rec !loc_list
let moving () =
try
let src = find (Join.self_location ()) in
Printf.printf "%s is moving\n" src
with
| Not_found -> failwith "Unknown location"
let create_loc s =
let loc a
def move b =
moving (); reply (Join.go b)
do {}
in
loc_list := (a,s) :: !loc_list;
a,move
;;
let a,m = create_loc "a" in
let b,m' = create_loc "b" in
m b;
m' Join.here
which has the following output:
schmitta@alan-schm1p:~/test> joc -o jpr jpr.ml
schmitta@alan-schm1p:~/test> ./jpr
a is moving
b is moving
Alan Schmitt
>I have a weird question :
>
>Is it possible to program a notion of self like you have with Thread.self ()
>in Ocaml ?
>
>The first question is what is self. The answer is the current most internal
>location of my thread. So what I am looking for is : self : unit -> location
>
>Why do I need it ? In fact the problem is linking a "service" (a
>function or a data structure identified by a "name") to the current
>location so that i can unambiguously refer to it without naming
>where I am. This mechanism has an ambiant flavour.
>
>I am ready to go very deep in the internals of jocaml to get this behaviour :
>is Jprims.self_location the function to look at ?
>
>Then there are two solutions :
> - put the service directly in the location structure :
> Is there a way to extract and call a process definition from the
> location_stub obtained ?
> - put the service in a global table with a location id as a key
> It is less efficient. A second problem is moving locations. I must
> move the elements using it as a key but also the sublocations.
>
>Thanks for any help !
>
>Pierre
>
>--
>Pierre Cregut - pierre.cregut@rd.francetelecom.fr - +33 2 96 05 16 28
>FTR&D - DTL/MSV - 2 avenue Pierre Marzin - 22307 Lannion Cedex - France
--
The hacker: someone who figured things out and made something cool happen.