why can't I call const methods on shared objects?
FreeSlave via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 11 00:33:38 PDT 2014
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
> method is executed, and then you may get wrong results.
>
> Consider:
>
> class Point
> {
> public:
> float x;
> float y;
>
>
> }
I send before I end(
class Point
{
public:
float x;
float y;
Tuple!(float, float) getLengthAndAngle() const
{
float l = sqrt(x*x+y*y);
//other thread change x or y
float a = atan2(x, y);
return tuple(l, a);
}
}
More information about the Digitalmars-d-learn
mailing list