This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Arrays with volatile elements

1 reply
DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
On Tue, Jan 13, 2009 at 11:53 AM, Philippe Monnaie <Philippe [dot] Monnaie [at] gmail [dot] com> wrote:
Nice!

Just out of interest, would it be possible in a similar way to allow
simultaneous updates in different parts of the array? Or am I asking
for too much?

I'm not sure what you mean. There's no synchronization going on here - you can update different parts of the array as you like. There are guarantees about visibility of changes to other threads (which does potentially slow things down quite a bit), but nothing to prevent concurrent update.
DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Arrays with volatile elements
On Tue, Jan 13, 2009 at 2:41 PM, Philippe Monnaie <Philippe [dot] Monnaie [at] gmail [dot] com> wrote:
Sorry, my mistake.

I was comparing it to using a lock for synchronizing an array in my
mind and messed up what I wanted to ask.

I was wondering whether it was possible to have slightly less strict
ordering guarantees.
I'll explain what I'm trying to say with an example. Let's have 2
threads: T1 and T2.

Suppose T1 does the following:
val number = sharedArray(0)
sharedArray(0) = number + 5
Console.print(sharedArray(0))

Suppose T2 does the following at the same time:
val number = sharedArray(5)
sharedArray(5) = number - 3
Console.print(sharedArray(5))

T1 and T2 don't really have much to do with each other and shouldn't
be updated about each other's actions until they need to know.

If I'm not mistaken, visibility of each other's changes is guaranteed
here, even if it is not needed as in the above example.

Is it possible to devise a way that would only guarantee the
visibility when there is actual interaction (or to limit the
visibility updates when there is no interaction)?

Ah, I see. No, I don't think so. Or at least I can't think of a useful way to do it (there are obvious high overhead ways of doing it, but I don't think that they'd actually buy you anything) 


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland