Version française
Home     About     Download     Resources     Contact us    
Browse thread
threads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: ygrek <ygrekheretix@g...>
Subject: Re: [Caml-list] threads
On Wed, 9 Sep 2009 01:20:06 +0200
Philippe Wang <philippe.wang.lists@gmail.com> wrote:

> >  let x = Array.make 100 []
> >  let update i n = x.(i) <- n :: x.(i)
> >  let read i = x.(i)
> 
> I don't think you can obtain funny results when you don't put a mutex
> on these two specific "update" and "read".
> What is sure is that "update" function is not atomic because you have
> a value allocation at the right of "<-" (with :: operator), and this
> may trigger garbage collection and/or make the scheduler change the
> running thread.

Yes, that's not a problem.

Thinking that over again it looks like the only issue remaining is the
possibility that compiler can be too smart and cache/reorder memory
operations, but ocamlopt is not of that kind, right?

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