From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: **** X-Spam-Status: No, score=4.1 required=5.0 tests=DNS_FROM_RFC_POST, RCVD_IN_SORBS_WEB,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 88403BBAF for ; Tue, 8 Sep 2009 19:33:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At0BALMxpkrRVdrRkGdsb2JhbACSA4h7PwEBAQEJCQwHEwOyH4EnKwiPNgEDAgQFgjcIgVAFgjY X-IronPort-AV: E=Sophos;i="4.44,353,1249250400"; d="scan'208";a="32414023" Received: from mail-bw0-f209.google.com ([209.85.218.209]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Sep 2009 19:33:29 +0200 Received: by bwz5 with SMTP id 5so2834425bwz.27 for ; Tue, 08 Sep 2009 10:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:x-mailer:mime-version:content-type; bh=6BWGqaYFu6sQIiFlzEKV7TUG0FLdATI+pC0FxDTYfEA=; b=kGLyhBvKuSk4v7a8FSJ0fH4Rdj29C3xYFUe95ZZsjdt+VQyeeM8IVqg+RlXUrZBOHB rJvSUbStOLLPeX78ak1fLaFutqJx4R8DjuSz8esZGxyTZJKCdiLhw93sXzgrFT5uaBPH rsItS1SexHmbE9iDOjtwwdwGBDFs58vgfDZX8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:x-mailer:mime-version:content-type; b=s3h0ccM5ZIGu9+kKRu7a6xSmWv+bkXFsaF3cZ9dtgU9lHABw8tBv7y+TcXzo8KTV19 JaTmyKeQqYj0ilL9pQc/oFRV9IAOtFISoPfk8FWhpwmgpjtF2t/c270PXT2DIOSXqt+N udCAMtFqGELH29SOLwNAhapulg03klcq60BvI= Received: by 10.204.156.217 with SMTP id y25mr13246296bkw.182.1252431208213; Tue, 08 Sep 2009 10:33:28 -0700 (PDT) Received: from lemon (109-19-133-95.pool.ukrtel.net [95.133.19.109]) by mx.google.com with ESMTPS id 1sm345444fkt.21.2009.09.08.10.33.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 08 Sep 2009 10:33:27 -0700 (PDT) Date: Tue, 8 Sep 2009 20:33:19 +0300 From: ygrek To: caml-list@yquem.inria.fr Subject: threads Message-Id: <20090908203319.cf4b1ff6.ygrekheretix@gmail.com> X-Mailer: Sylpheed 2.5.0 (GTK+ 2.12.12; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="PGP-SHA1"; boundary="Signature=_Tue__8_Sep_2009_20_33_19_+0300_9vcSZPz.RqOUy5It" X-Spam: no; 0.00; ocaml:01 ocamlopt:01 threads:01 functions:01 writes:01 cached:02 mutex:03 let:03 let:03 correctly:04 thread:06 thread:06 uses:07 reads:08 memory:09 X-Attachments: type="application/pgp-signature" --Signature=_Tue__8_Sep_2009_20_33_19_+0300_9vcSZPz.RqOUy5It Content-Type: text/plain; charset=US-ASCII Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, let x =3D Array.make 100 [] let update i n =3D x.(i) <- n :: x.(i) let read i =3D 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?=20 I.e. is Array.set atomic? What about updating references (:=3D) ? 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? --=20 ygrek http://ygrek.org.ua --Signature=_Tue__8_Sep_2009_20_33_19_+0300_9vcSZPz.RqOUy5It Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkqmlV8ACgkQY0a5RXCNWgwqzgCgtWPyJfJ7oKwz7KjwvZ3yXlBF 5osAoIqByOftvF/AVNHx/brDuAJtTAHY =88/f -----END PGP SIGNATURE----- --Signature=_Tue__8_Sep_2009_20_33_19_+0300_9vcSZPz.RqOUy5It--