From: David Brown <caml-list@davidb.org>
To: Janne Hellsten <janne@hybrid.fi>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Unix module and threads
Date: Sun, 5 Sep 2004 06:32:43 -0700 [thread overview]
Message-ID: <20040905133243.GB15531@old.davidb.org> (raw)
In-Reply-To: <413AC784.4010007@hybrid.fi>
[-- Attachment #1: Type: text/plain, Size: 567 bytes --]
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
[-- Attachment #2: threa.ml --]
[-- Type: text/plain, Size: 733 bytes --]
(* 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
next prev parent reply other threads:[~2004-09-05 13:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-05 8:00 Janne Hellsten
2004-09-05 13:32 ` David Brown [this message]
2004-09-05 13:42 ` Markus Mottl
2004-09-05 13:53 ` Janne Hellsten
2004-09-05 15:27 ` skaller
2004-09-06 9:07 ` Keith Wansbrough
2004-09-05 13:57 ` Daniel Andor
2004-09-05 15:12 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040905133243.GB15531@old.davidb.org \
--to=caml-list@davidb.org \
--cc=caml-list@inria.fr \
--cc=janne@hybrid.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox