English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Threads library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-11-23 (16:32)
From: Ernesto Posse <eposse@c...>
Subject: Re: [Caml-list] Threads library

  Thanks John. It worked.

  I do have another question, and it is about the behaviour of Thread.join.

  I have the following definitions:

open Thread;;

let rec f = function 0 -> () | n -> print_int n; f(n-1);;

let pp (x, y) = (create f x, create f y);;

let ppp = create pp;;

let jpp x y = join(ppp (x,y));

  I would expect that invoking

jpp 8 9;;

  would force the prompt to appear after all threads from ppp(x,y) have
ended, but this doesn't appear to be the case. If I understand
correctly, the join affects only the thread created by ppp, but not
those spawned from it. Is there a simple way to join the rest of the
threads created?

> On Mon, 22 Nov 2004 16:20:31 -0500 (EST), Ernesto Posse
> <eposse@cs.mcgill.ca> wrote:
>>   Hi. I have a problem with the threads library. Basically I am unable
>> to
>> access the library.
>>   The libraries are installed in the default location
>> (/usr/local/lib/ocaml) (I installed version 3.08.1, on linux
>> 2.6.4-54.5-smp on i686, running SuSE)
>   {...}
> There are two things that will help you here.  The first is that you
> want to run your toplevel like this:
> ocaml -I +threads
> in order to make sure that the threading libraries (and more
> importantly, the thread interfaces!) are on the ocaml include path.
> This is *the* most important point, since when you try to refer to the
> Threads module, the toplevel is going to look in its path to find the
> .mli files, regardless of what has been linked in.
> The second thing is that the order in which you #load is relevant.  If you
> do:
> #load "threads.cma";;
> #load "unix.cma";;
> threads isn't actually loaded--it failed to load.  I suspect you
> figured that part out, however.
> So, if you just do the -I +threads and then #load "threads.cma"
> instead of #load ".../lib/ocaml/threads.cma", you'll succeed for the
> normal toplevel.  And with the custom toplevel, you'll still need to
> include -I +threads.  You can also use:
> #directory "+threads";;
> to add to the include path of a running ocaml process.
> And as a final note, if you have installed findlib, you can either
> make a toplevel with topfind compiled in, or:
> #use "topfind";;
> in order to get the findlib toplevel extensions.  This will let you do:
> #thread;;
> to enable threading.  (It adds +threads to the include path, then
> loads unix and threads.)
> Hope this helps!
> John.

Ernesto Posse
Modelling, Simulation and Design Lab - School of Computer Science
McGill University - Montreal, Quebec, Canada
url: http://moncs.cs.mcgill.ca/people/eposse