@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...
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
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.
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
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
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.
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.
Is this still the case if the method is const or pure?
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)?
I mean I thought that's what pure was for but the compiler
complains all the same.
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
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
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
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.
14 matches
Mail list logo