Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 15, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 Atila Neves <atila.neves@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |rejects-valid -- |
February 15, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |razvan.nitu1305@gmail.com --- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> --- Actually, the issue does not seem to have anything to do with synchronized (although, looking at the code it seems that Synchronized Statements have their own issues), but rather that you cannot create shared objects: class Class {} void main() { auto b = new shared Class(); // Error: direct access to shared `new shared(Class)` is not allowed, see `core.atomic` } This is ridiculous, so you can't create shared objects with new? -- |
February 15, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 --- Comment #2 from Atila Neves <atila.neves@gmail.com> --- Oh, wow. I assumed the problem was with `synchronized` because the problem being with `new shared Class` was just too fundamental to even consider! -- |
February 15, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|major |regression --- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> --- This is actually a 2.095 regression. -- |
February 15, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> --- @RazvanN7 created dlang/dmd pull request #14884 "Fix Issue 23709 - Cannot use synchronized on shared class with -preview=nosharedaccess" fixing this issue: - Fix Issue 23709 - Cannot use synchronized on shared class with -preview=nosharedaccess https://github.com/dlang/dmd/pull/14884 -- |
February 15, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 --- Comment #5 from Atila Neves <atila.neves@gmail.com> --- This is actually two bugs: creating a shared instance isn't possible with new, but the bug description is still accurate since this doesn't compile: class Class {} void main() { shared Class c; synchronized(c) {} } % d.d(4): Error: direct access to shared `c` is not allowed, see `core.atomic` -- |
February 22, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 --- Comment #6 from Atila Neves <atila.neves@gmail.com> --- I submitted a new issue: https://issues.dlang.org/show_bug.cgi?id=23732 -- |
March 21, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #7 from RazvanN <razvan.nitu1305@gmail.com> --- This is not a bug. The compiler rewrites the code to: auto tmp = c; _d_monitorenter(tmp); try { body } finally { _d_monitorexit(tmp); } So the reading of c needs to be atomic. Note that the original example (synchronized(new shared Class)) currently compiles because creating a shared instance does not need to be protected by a mutex. So just write: import core.atomic; class Class {} void main() { shared Class c; synchronized(atomicLoad(c)) {} } And the code will compile. Arguably, the compiler could automatically wrap `c` into an `atomicLoad`, however, that's based on the assumption that druntime is available and that the users does not employ a different synchronization mechanism. I will tentatively close this as INVALID, but please reopen if I am missing something. -- |
March 21, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 mhh <maxhaton@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxhaton@gmail.com --- Comment #8 from mhh <maxhaton@gmail.com> --- If the monitor bit is synchronized does the load of c need to be atomic? -- |
March 22, 2023 [Issue 23709] Cannot use synchronized on shared class with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23709 --- Comment #9 from RazvanN <razvan.nitu1305@gmail.com> --- (In reply to mhh from comment #8) > If the monitor bit is synchronized does the load of c need to be atomic? Yes, because the pointer to the class could be modified before entering the monitor function. -- |
Copyright © 1999-2021 by the D Language Foundation