From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA19368; Tue, 1 Jul 2003 17:24:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA18077 for ; Tue, 1 Jul 2003 17:24:13 +0200 (MET DST) Received: from smtp018.mail.yahoo.com (smtp018.mail.yahoo.com [216.136.174.115]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id h61FOBf06537 for ; Tue, 1 Jul 2003 17:24:12 +0200 (MET DST) Received: from l01m-20-28.d0.club-internet.fr (tofm2@195.36.239.28 with plain) by smtp.mail.vip.sc5.yahoo.com with SMTP; 1 Jul 2003 15:24:10 -0000 Subject: Re: [Caml-list] Threads & the order that module initialization code runs From: Michel Christophe Reply-To: tofm2@yahoo.fr To: Richard Jones Cc: caml-list@inria.fr In-Reply-To: <20030701133415.GA28214@redhat.com> References: <20030701133415.GA28214@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Message-Id: <1057073048.2795.3.camel@msi.ratatatator.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4-1.1mdk Date: 01 Jul 2003 17:24:08 +0200 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; caml-list:01 threads:01 simulating:01 ecrit:01 christophe:01 modules:02 thread:02 module:03 bunch:03 let:04 michel:04 array:04 ------:94 seems:05 queue:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Thanks for answers Le mar 01/07/2003 à 15:34, Richard Jones a écrit : > A quick question about threads: > > I have a few modules simulating a network and some machines connected > to the network. > > In, for example, network.ml, I have a bunch of initialization code at > the top level: > > --- network.ml --- > let new_queue i = > (Queue.create (), > Mutex.create (), > Condition.create ()) in > let out_queue = Array.init nr_machines new_queue > > (* There is one queue of incoming messages to the network thread. *) > let in_queue = Queue.create () > > (* Mutex/condition protecting the in_queue. *) > let in_mutex = Mutex.create () > let in_cond = Condition.create () > ------ > > And also I have a Main module which starts up the threads: > > --- main.ml --- > (* Create a thread to simulate the network. *) > let network_thread = Thread.create Network.run ();; > > (* Start a thread for each of the simulated machines. *) > let machine_thread = Array.init nr_machines (Thread.create Machine.run);; > ------ > > It's obviously going to be a problem if the initialization code in > Network hasn't run by the time the machine threads have been started > up in Main (or if the network thread itself gets started up first). > > Now it all seems to work, but am I being lucky or do module > initializers run in some sort of well-defined order I can depend on? > > Rich. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners