can we add such feature? synchronized(null) ==> i.e NO-OP
mw
mingwu at gmail.com
Fri Aug 26 20:49:52 UTC 2022
On Friday, 26 August 2022 at 19:47:18 UTC, Paul Backus wrote:
> On Friday, 26 August 2022 at 19:26:12 UTC, mw wrote:
>> On Friday, 26 August 2022 at 18:51:06 UTC, Paul Backus wrote:
>>> Since `innerBlock` has access to `foo`'s parameters via its
>>> context, you should not need to do any complicated
>>> refactoring.
>>
>> Yes, it's the same solution I end up with.
>>
>> However, I still think synchronized(null) ==> NOOP is a better
>> semantics than NPE.
>>
>> Then I don't even need such innerBlock(), and the if-else.
>
> I guess another possibility is something like this:
>
> ```d
> void foo(...) {
> scope Object fakeLock = new Object; // allocated on stack
> Object lock = condition ? realLock : fakeLock
>
> synchronized (lock) {
> // code here
> }
> }
> ```
>
> Since `fakeLock` is local to the function, synchronizing on it
> should be effectively a no-op.
Thanks.
Is there any documentation for creating class object on the stack?
I only found this discussion:
https://forum.dlang.org/thread/srbzvjezicpuhxhzzoyb@forum.dlang.org?page=2
Also I want confirmation that this scope usage will not be
deprecated in the future.
More information about the Digitalmars-d
mailing list