--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
For the JVM—assume that something is thread unsafe unless explicitly stated otherwise.
On Fri, Mar 7, 2014 at 8:04 AM, √iktor Ҡlang <viktor...@gmail.com> wrote:
For the JVM—assume that something is thread unsafe unless explicitly stated otherwise.
So if scala.collection.mutable.Queue is thread safe
, what is the purpose of scala.collection.mutable.SynchronizedQueue ?
Andy
So if scala.collection.mutable.Queue is thread safeWho said it is?
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andy, the problem with mutable data-structures that claim to be thread-safe is that thread-safe operations are not composable. So if you do a data.get() before a data.set(), the result will be unsafe, making the whole thread-safety claim pretty useless, unless you have compare-and-swap semantics. This is why mutable data-structures on the JVM are usually not thread-safe, since locks have overhead and you'll need higher level locks anyway.
As Tim said, use an immutable queue and if mutability is required just stick that in an AtomicReference - best thing since slice bread.
--
Andy - If you want easier concurrency, you should be looking at immutable stuff and a functional approach and/or akka.
These days my code has almost no vars and makes almost no use of mutable structures.