Bug 18468 – cannot use `synchronized {}` in @safe code

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2018-02-19T12:00:44Z
Last change time
2018-02-24T11:44:17Z
Keywords
pull
Assigned to
No Owner
Creator
Nicholas Wilson

Comments

Comment #0 by iamthewilsonator — 2018-02-19T12:00:44Z
@safe void main() { synchronized {} } onlineapp.d(4): Error: safe function 'main' cannot access __gshared data '__critsec15' onlineapp.d(4): Error: safe function 'main' cannot access __gshared data '__critsec15' onlineapp.d(4): Error: variable onlineapp.main.__critsec15 __gshared not allowed in safe functions; use shared this is due to the compiler rewriting synchronized { foo();} // line 15 as __gshared ubyte[critsec.sizeof + size_t.sizeof] __critsec15; _d_criticalenter(__critsec15.ptr); try { foo(); } finally { _d_criticalexit(__critsec15.ptr); } instead of __gshared ubyte[critsec.sizeof + size_t.sizeof] __critsec15; _d_criticalenter(&__critsec15[0]); try { foo(); } finally { _d_criticalexit(&__critsec15[0]); }
Comment #1 by iamthewilsonator — 2018-02-19T12:09:31Z
Im an idiot and can't read, still this should work.
Comment #2 by greensunny12 — 2018-02-19T15:09:40Z
Yep, looks like this is really trivial to fix: https://github.com/dlang/dmd/pull/7918
Comment #3 by github-bugzilla — 2018-02-24T11:44:12Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/8130ab0a5181e3a71442a7014ebc5159331a9d2e Fix Issue 18468 - cannot use `synchronized {}` in @safe code https://github.com/dlang/dmd/commit/f06b5ef86be01db8ca0b116bc5499a9d10e2a6a5 Merge pull request #7918 from wilzbach/fix-18468 Fix Issue 18468 - cannot use `synchronized {}` in @safe code merged-on-behalf-of: Mike Franklin <[email protected]>