<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/ffad81dd218cf6853f9aa8fb285ee831"
  from="Michel Christophe &lt;tofm2@y...&gt;"
  author="Michel Christophe"
  date="2003-07-01T15:24:14"
  subject="Re: [Caml-list] Threads &amp; the order that module initialization code runs"
  prev="2003/07/4507fc0e2df3c31d3ba322eb9ac0ad48"
  next="2003/07/df9282654273ab424718f1aad9ecb492"
  prev-in-thread="2003/07/17fd8703a229fabb92df42fcba4d10cf"
  next-in-thread="2003/07/048faa0f5ab032b75abc596f2cb84132"
  prev-thread="2003/07/cb5a4b17681aa3d47372f3e2b2c6ece0"
  next-thread="2003/07/4b91558ac368a708608e0af3e7e348f2"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Threads &amp; the order that module initialization code runs">
<msg 
  url="2003/07/17fd8703a229fabb92df42fcba4d10cf"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-01T13:34:21"
  subject="[Caml-list] Threads &amp; the order that module initialization code runs">
<msg 
  url="2003/07/ffad81dd218cf6853f9aa8fb285ee831"
  from="Michel Christophe &lt;tofm2@y...&gt;"
  author="Michel Christophe"
  date="2003-07-01T15:24:14"
  subject="Re: [Caml-list] Threads &amp; the order that module initialization code runs">
</msg>
<msg 
  url="2003/07/048faa0f5ab032b75abc596f2cb84132"
  from="Yamagata Yoriyuki &lt;yoriyuki@m...&gt;"
  author="Yamagata Yoriyuki"
  date="2003-07-01T23:15:10"
  subject="Re: [Caml-list] Threads &amp; the order that module initialization code runs">
</msg>
</msg>
</thread>

<contents>
Thanks for answers



Le mar 01/07/2003 à 15:34, Richard Jones a écrit :
&gt; A quick question about threads:
&gt; 
&gt; I have a few modules simulating a network and some machines connected
&gt; to the network.
&gt; 
&gt; In, for example, network.ml, I have a bunch of initialization code at
&gt; the top level:
&gt; 
&gt; --- network.ml ---
&gt; let new_queue i =
&gt;   (Queue.create (),
&gt;    Mutex.create (),
&gt;    Condition.create ()) in
&gt; let out_queue = Array.init nr_machines new_queue
&gt; 
&gt; (* There is one queue of incoming messages to the network thread. *)
&gt; let in_queue = Queue.create ()
&gt; 
&gt; (* Mutex/condition protecting the in_queue. *)
&gt; let in_mutex = Mutex.create ()
&gt; let in_cond = Condition.create ()
&gt; ------
&gt; 
&gt; And also I have a Main module which starts up the threads:
&gt; 
&gt; --- main.ml ---
&gt; (* Create a thread to simulate the network. *)
&gt; let network_thread = Thread.create Network.run ();;
&gt; 
&gt; (* Start a thread for each of the simulated machines. *)
&gt; let machine_thread = Array.init nr_machines (Thread.create Machine.run);;
&gt; ------
&gt; 
&gt; It's obviously going to be a problem if the initialization code in
&gt; Network hasn't run by the time the machine threads have been started
&gt; up in Main (or if the network thread itself gets started up first).
&gt; 
&gt; Now it all seems to work, but am I being lucky or do module
&gt; initializers run in some sort of well-defined order I can depend on?
&gt; 
&gt; 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

</contents>

</message>

