Synchronized classes have no public members

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 13 12:12:09 PDT 2015


On Tuesday, 13 October 2015 at 19:05:31 UTC, Dicebot wrote:
> On Tuesday, 13 October 2015 at 18:28:23 UTC, Marco Leise wrote:
>> Guys, sorry to break into your wishful thinking, but
>>
>>    synchronized(mutex) {}
>>
>> already works as you want it to since as long as I can think. 
>> Yes, it takes a parameter, yes it calls lock/unlock on the 
>> mutex. :)
>
> Yes, and I am saying that it doesn't justify presence of 
> `synchronized` keyword in the language at all, being historical 
> legacy misfeature.

The same can be done trivially with a guard/autolock object, 
because we have RAII. It can also be done with scope statements, 
though that's more verbose. I suspect that C# has it primarily 
because they don't have RAII.

I don't know that it really hurts D to have synchronized 
statements, but I do agree that they really don't add much in the 
way of value. And it's not like it's hard to come up with cases 
where they don't even work, whereas a guard/autolock could (e.g. 
having to unlock the mutex partway through a block, possibly 
relocking it later in the block, possibly not).

- Jonathan M Davis


More information about the Digitalmars-d mailing list