digitalmars.D - How synchronized actually works?
- Hipreme (34/35) Dec 01 2023 I was almost going to implement a thing which I would call
- Nick Treleaven (3/6) Dec 04 2023 I've made a PR to improve the docs:
- Hipreme (4/10) Dec 05 2023 Almost missed it out but wanted to let you know, thanks a bunch
I was almost going to implement a thing which I would call
`Locked`, by using that code:
```d
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
```d
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.
Dec 01 2023
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
Dec 04 2023
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: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 :)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
Dec 05 2023








Hipreme <msnmancini hotmail.com>