caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: ygrek <ygrekheretix@gmail.com>
To: caml-list@yquem.inria.fr
Subject: threads
Date: Tue, 8 Sep 2009 20:33:19 +0300	[thread overview]
Message-ID: <20090908203319.cf4b1ff6.ygrekheretix@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 759 bytes --]

Hello,

 let x = Array.make 100 []
 let update i n = x.(i) <- n :: x.(i)
 let read i = x.(i)

 Consider the following scenario: one thread is `update`ing x, another
thread(s) uses only `read`. Is it safe to use these functions without
locking on mutex? 

 I.e. is Array.set atomic? What about updating references (:=) ?

 If I understand correctly these operations require only one cpu
instruction to update one machine word and so should be atomic. Taking
into account "single-cpu affinity" of ocaml program it should be safe
to write such multithreaded code. Is it true?

 Is it safe to assume that ocamlopt won't skip reads/writes to globally
visible memory address using cached value in a register?

-- 
 ygrek
 http://ygrek.org.ua

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

             reply	other threads:[~2009-09-08 17:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-08 17:33 ygrek [this message]
2009-09-08 23:20 ` [Caml-list] threads Philippe Wang
2009-09-10 18:17   ` ygrek
  -- strict thread matches above, loose matches on Subject: below --
2005-06-10 17:56 Threads Jonathan Bryant

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=20090908203319.cf4b1ff6.ygrekheretix@gmail.com \
    --to=ygrekheretix@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).