Re: why can't I call const methods on shared objects?

2014-05-12 Thread Vlad Levenfeld via Digitalmars-d-learn
@FreeSlave John Colvin Yes, I see your point. I could still get tearing on a read. So, in the case of methods that I believe are safe (e.g. 1-line @property getters) I'll just write a shared variadic function template that uses (cast()this).foo(args) to forward to the non-shared method...

Re: why can't I call const methods on shared objects?

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 11 May 2014 at 07:31:10 UTC, FreeSlave wrote: On Friday, 9 May 2014 at 21:42:14 UTC, Vlad Levenfeld wrote: Is this still the case if the method is const or pure? Const methods still require synchronization, because other threads may change some data, needed by const method while

Re: why can't I call const methods on shared objects?

2014-05-11 Thread FreeSlave via Digitalmars-d-learn
On Friday, 9 May 2014 at 21:42:14 UTC, Vlad Levenfeld wrote: Is this still the case if the method is const or pure? Const methods still require synchronization, because other threads may change some data, needed by const method while method is executed, and then you may get wrong results.

Re: why can't I call const methods on shared objects?

2014-05-11 Thread John Colvin via Digitalmars-d-learn
On Friday, 9 May 2014 at 21:37:37 UTC, Vlad Levenfeld wrote: Error: non-shared const method is not callable using a shared mutable object Why not? If the method is const, it can't modify the object anyway. Because thread-safety isn't only a problem when writing to memory, reads must also

Re: why can't I call const methods on shared objects?

2014-05-11 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 9 May 2014 at 21:58:41 UTC, Steven Schveighoffer wrote: On Fri, 09 May 2014 17:45:37 -0400, Vlad Levenfeld vlevenf...@gmail.com wrote: Is there any way to declare a method as safe regardless of shared/mutability/etc (or some other way to avoid cast(Type)object.property every time

why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
Error: non-shared const method is not callable using a shared mutable object Why not? If the method is const, it can't modify the object anyway.

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Fri, 09 May 2014 17:37:35 -0400, Vlad Levenfeld vlevenf...@gmail.com wrote: Error: non-shared const method is not callable using a shared mutable object Why not? If the method is const, it can't modify the object anyway. Non-shared methods cannot be called on shared objects.

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
Is this still the case if the method is const or pure?

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
Is there any way to declare a method as safe regardless of shared/mutability/etc (or some other way to avoid cast(Type)object.property every time I want to check a property which won't affect any state)?

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
I mean I thought that's what pure was for but the compiler complains all the same.

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Fri, 09 May 2014 17:45:37 -0400, Vlad Levenfeld vlevenf...@gmail.com wrote: Is there any way to declare a method as safe regardless of shared/mutability/etc (or some other way to avoid cast(Type)object.property every time I want to check a property which won't affect any state)? Not

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
Let me see if I understand this right... let's say I have some (unshared) class that launches threads to do its real work in. class Foo { this () {thread = spawn (work);} shared void work () {...}; void send_message (T) (T msg) {thread.send (msg);} Tid thread; } It has an unshared

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
PS After reading your post I experimented with overloading shared/unshared methods in my code and came up with this solution: shared Id!Service id ()() const if (is (typeof(this) == shared)) { return (cast(Service)this).id; } Id!Service id () const { return service_id; } I like this better

Re: why can't I call const methods on shared objects?

2014-05-09 Thread Vlad Levenfeld via Digitalmars-d-learn
aaand on further experimentation it turns out I don't need a template at all, I can just overload it... strange, I seem to remember not being able to do that before.