Thread overview
How synchronized actually works?
Dec 01
Hipreme
Dec 05
Hipreme
December 01

I was almost going to implement a thing which I would call Locked, by using that code:

struct Locked
{
    private Mutex mtx;
    this(Mutex mtx)
    {
        this.mtx = mtx;
        mtx.lock();
    }
    ~this()
    {
        mtx.unlock();
    }
}

with(Locked(myMutex))
{
}

But then I remembered D has a keyword called synchronized. Then I looked at the spec, and I was overjoyed by the example present on it:

>

Example

synchronized { ... }

I really loved this example and I think it should be reproduced in a big screen everywhere in the world (complete sarcasm).

I'm wanting someone more experienced in the subject to both explain in this thread and update the spec: (https://dlang.org/spec/statement.html#synchronized-statement)

Also, there has been a talk on Discord for it being a Range-like interface, but for lock and unlock, instead of using only classes object but I don't understand enough about this subject.

December 04

On Friday, 1 December 2023 at 21:01:32 UTC, Hipreme wrote:

>

I'm wanting someone more experienced in the subject to both explain in this thread and update the spec: (https://dlang.org/spec/statement.html#synchronized-statement)

I've made a PR to improve the docs:
https://github.com/dlang/dlang.org/pull/3739

December 05

On Monday, 4 December 2023 at 13:05:38 UTC, Nick Treleaven wrote:

>

On Friday, 1 December 2023 at 21:01:32 UTC, Hipreme wrote:

>

I'm wanting someone more experienced in the subject to both explain in this thread and update the spec: (https://dlang.org/spec/statement.html#synchronized-statement)

I've made a PR to improve the docs:
https://github.com/dlang/dlang.org/pull/3739

Almost missed it out but wanted to let you know, thanks a bunch for the work! It is a lot better now and I can clearly understand what it is supposed to do :)