On Monday, 1 October 2018 at 02:29:40 UTC, Manu wrote:
So, I know that there's not a bunch of threads banging on this object... but the shared method should still work! A method that handles thread-safety doesn't suddenly not work when it's only accessed from a single thread.
Shared data may need different algorithms. If unshared data is implicitly convertible to shared, you start to conflate shared data with unshared, so you're back to C-style sharing.
This is how you can do it: shared struct SharedBob { this(int){} void setThing(){} } alias shared SharedBob Bob; void f(ref shared Bob a, ref Bob b) { a.setThing(); // I have a shared object, can call shared method b.setThing(); // ok } int main() { auto b=Bob(0); Bob c; f(b,c); return 0; }