Bug 3089 – Error: f.bar can only be called on a mutable object, not shared(foo)

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2009-06-23T20:05:00Z
Last change time
2015-06-09T01:27:58Z
Keywords
rejects-valid
Assigned to
nobody
Creator
jason.james.house

Attachments

IDFilenameSummaryContent-TypeSize
401error.dSample code demonstrating the issuetext/x-dsrc97

Comments

Comment #0 by jason.james.house — 2009-06-23T20:05:21Z
Created attachment 401 Sample code demonstrating the issue The compiler seems to offer no way to call functions on shared structs/classes under certain scenarios. The attached code demonstrates the simplest case I could find. Changing the type of foo to class, or moving the shared keyword on the function bar has no effect.
Comment #1 by sandford — 2009-08-07T14:43:50Z
I've found const functions are callable on shared objects: struct foo{ int bar() const { return 1; } } void main(){ shared foo f; auto x = f.bar; }
Comment #2 by dfj1esp02 — 2009-10-28T09:55:31Z
That's because struct has no monitor member, so the callee can't lock it for exclusive access.
Comment #3 by sandford — 2009-10-28T10:06:11Z
To the best of my knowledge, currently, shared does not imply synchronized, though synchronized implies shared. Shared only provides the correct memory fences. Shared structs/arrays are important for lock-free algorithms.
Comment #4 by jason.james.house — 2009-10-28T10:55:53Z
(In reply to comment #3) > To the best of my knowledge, currently, shared does not imply synchronized, > though synchronized implies shared. Shared only provides the correct memory > fences. Shared structs/arrays are important for lock-free algorithms. That's the exact use case I want to do!
Comment #5 by bugzilla — 2009-10-28T11:30:10Z
Works in dmd 2.035.