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!