<div class="gmail_quote">On Tue, Oct 25, 2011 at 1:26 AM, Benjamin Thaut <span dir="ltr"><<a href="mailto:code@benjamin-thaut.de">code@benjamin-thaut.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Am 25.10.2011 08:06, schrieb Andrew Wiley:<div><div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Geez, I try to write some multithreaded code and I just keep hitting these:<br>
--------<br>
module test3;<br>
<br>
struct SomeData {<br>
int i;<br>
int iPlus2() {<br>
return i + 2;<br>
}<br>
}<br>
<br>
synchronized class Bob {<br>
private:<br>
SomeData _dat;<br>
public:<br>
this() {<br>
_dat.i = 3;<br>
}<br>
@property<br>
int i() {<br>
return _dat.iPlus2(); // test3.d(22): Error: function<br>
test3.SomeData.iPlus2 () is not callable using argument types () shared<br>
}<br>
}<br>
--------<br>
<br>
This seems like it should be legal because SomeData is a value type.<br>
Accessing _dat.i directly is legal, and _dat can't possibly be shared.<br>
If I'm understanding things correctly, transitive shared shouldn't apply<br>
to value types like this, so the type of "this" when calling iPlus2<br>
should just be SomeData.<br>
</blockquote>
<br></div></div>
It can't be garantueed that a pointer to _dat is not given away at some point in the program. For example you could have a clas Foo that inherits from Bob and has a getter for _dat. Then it wouldn't be correct anymore to sasume _dat is unshared. Because of that it has been decided that trying to figure out if _dat has to be shared or not will not happen, thus its just shared always. I've already reported this some time ago and essentially it makes synchronized classes useless for me. I usually just write a normal class and but the synchronized blocks in myself. Also I use __gshared ;-)</blockquote>
<div><br></div><div>Alright, but why can I access _dat.i without synchronization? </div></div>