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

Re: Synchronized*

3 replies
Seth Tisue
Joined: 2008-12-16,
User offline. Last seen 34 weeks 3 days ago.

>>>>> "David" == David MacIver writes:

David> Hi, I was talking to paul about this in #scala and basically
David> came to the conclusion that SynchronizedMap, SynchronizedBuffer,
David> etc. are actually a terrible idea. I would like to advocate
David> their removal in 2.8 (or at least their extreme deprecation

+1

David> synchronizing all the methods is not a good way to add thread
David> safety to a class anyway. If this is the best one can do for a
David> class then it's uniformly better to declare it to not be
David> threadsafe and manage synchronization externally.

+1,000,000

Iulian Dragos 2
Joined: 2009-02-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Synchronized*

On May 26, 2009, at 11:37 PM, Seth Tisue wrote:

> David> synchronizing all the methods is not a good way to add thread
> David> safety to a class anyway. If this is the best one can do for a
> David> class then it's uniformly better to declare it to not be
> David> threadsafe and manage synchronization externally.
>
> +1,000,000

But isn't this exactly what they do?

iulian

>

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Synchronized*

I think SynchronizedMaps are very useful form a client perspective. I
needed them myself in the Scala Eclipse IDE. Workarounds from clients
are probably worse than the functionality provided by SynchronizedMap.
Sure, you have to be careful when extending the collection classes,
and also when creating your own maps. But these are the rare cases.
The most common case is that you want to take a standard map
implementation off the shelf and make it synchronized.
So, for all their shortcomings I believe that SynchronizedMap/Set are
essential ingredients of a collection library.

Cheers

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Synchronized*

I should mention that the problems with SynchronizedMap could also be
interpreyted as a shortcoming of the language. What you want is a
form of quantification, that you can mixin a feature to all methods of
a class or trait automatically, or by a wildcard. AOP can do that, of
course, but it comes with lots of other features entangled with it.

Cheers

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