On Mon, Aug 31, 2009 at 6:07 PM, Dave
Griffith<
dave.l.griffith <at> gmail.com> wrote:
>
>
>
> Rodrigo Cano wrote:
>>
>> Yes, I perfectly understand what synchronized is for, I had worked a lot
>> with threads in java, and know how to use it, thank you.
>>
>
> Well, no, evidently not.
>
> "synchronized" in Scala is purely more powerful that "synchronized" in Java.
> The T0 is a type parameter, not a by-name parameter. It means that the
> "synchronized" method in Scala can evaluate to a value (unlike the
> "synchronized" statement in Java). The value returned by the synchronized
> method is whatever is returned by the argument to the synchronized method.
> In your case, that return is of type "Unit" (similar to "void" in Java)
> since that's the type that the last expression in your synchronized
> statement's argument has. Most of the time, you don't have to explicitly
> specify T0, since Scala's type inference will do that for you.
>
> Also, this would be a good place to say that you really don't want to mix
> actor semantics with low-level thread-wrangling semantics like
> "synchronized" (or "wait", or "notify"). Do that naively, and the best you
> can hope for is an ugly deadlock. After that things get more difficult to
> diagnose.
>
> In general, anything you see in Scala that looks similar to something in
> Java will be just similar enough to tweak your intuition, but not similar
> enough for you to actually understand it fully.
>
> --Dave Griffith
>
> --
> View this message in context:
http://www.nabble.com/How-to-use-synchronized--tp25228291p25232855.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>