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 PAA19390; Sun, 5 Sep 2004 15:32:47 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA20064 for ; Sun, 5 Sep 2004 15:32:45 +0200 (MET DST) Received: from mail.davidb.org (adsl-64-172-240-129.dsl.sndg02.pacbell.net [64.172.240.129]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i85DWhKF032423 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 5 Sep 2004 15:32:45 +0200 Received: from davidb by mail.davidb.org with local (Exim 4.41 #1 (Debian)) id 1C3x8N-00048u-0T; Sun, 05 Sep 2004 06:32:43 -0700 Date: Sun, 5 Sep 2004 06:32:43 -0700 From: David Brown To: Janne Hellsten Cc: caml-list@inria.fr Subject: Re: [Caml-list] Unix module and threads Message-ID: <20040905133243.GB15531@old.davidb.org> References: <413AC784.4010007@hybrid.fi> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="tThc/1wpZn/ma/RB" Content-Disposition: inline In-Reply-To: <413AC784.4010007@hybrid.fi> User-Agent: Mutt/1.5.6i X-Miltered: at concorde with ID 413B157B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 caml-list:01 threads:01 2004:99 foo:01 threads:01 implemented:01 varies:01 printf:01 printf:01 getcwd:01 compiler:01 05,:01 sep:01 native:02 X-Attachments: name="threa.ml" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Sep 05, 2004 at 11:00:04AM +0300, Janne Hellsten wrote: > I wonder what happens if I call [Unix.chdir foo] from two different > threads, with two different directories? I think this is going to depend on how threads are implemented, and as I understand it, that varies depending on what platform, and which compiler you are using. I've attached a small program that will help determine this. As far as I can tell, on Linux, there seems to only be one current directory shared between all of the threads. This is the same for native and byte-code. Dave --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="threa.ml" (* Show chdir and threads. *) let phase = ref 0 let phase_lock = Mutex.create () let phase_cond = Condition.create () let wait_phase n = Mutex.lock phase_lock; while !phase != n do Condition.wait phase_cond phase_lock done; Mutex.unlock phase_lock let mark_phase n = Mutex.lock phase_lock; phase := n; Condition.signal phase_cond; Mutex.unlock phase_lock let thread_a () = wait_phase 1; Unix.chdir "a"; mark_phase 2; wait_phase 3 let thread_b () = (* Execution starts here. *) mark_phase 1; wait_phase 2; Printf.printf "result dir: %S\n" (Unix.getcwd ()); mark_phase 3 let () = let a = Thread.create thread_a () in let b = Thread.create thread_b () in Thread.join a; Thread.join b --tThc/1wpZn/ma/RB-- ------------------- 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