<div class="gmail_quote">On Tue, Oct 18, 2011 at 12:53 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 17.10.2011 22:43, schrieb Michel Fortin:<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">
On 2011-10-17 20:33:59 +0000, Andrew Wiley <<a href="mailto:wiley.andrew.j@gmail.com" target="_blank">wiley.andrew.j@gmail.com</a>> said:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Okay, I realize there have been some discussions about this, but I have a<br>
few questions about shared delegates because right now they are<br>
definitely<br>
broken, but I'm not sure how.<br>
Take this code example:<br>
<br>
synchronized class Thing {<br>
void doSomeWork(void delegate() work) {<br>
work();<br>
}<br>
void work() {}<br>
}<br>
<br>
void main() {<br>
auto th = new Thing();<br>
th.doSomeWork(&th.work);<br>
}<br>
<br>
This doesn't compile because the type of "&th.work" is "void delegate()<br>
shared", which cannot be cast implicitly to "void delegate()".<br>
My first question would be whether that type is correct. It's true<br>
that the<br>
data pointer of the delegate points to a shared object, but given that<br>
the<br>
function locks it, does that really matter in this case? I guess I'm just<br>
not clear on the exact meaning of "shared" in general, but it seems like<br>
whether the data is shared or not is irrelevant when the delegate<br>
points to<br>
a public member of a synchronized class. If it was a delegate pointing<br>
to a<br>
private/protected member (which should be illegal in this case), that<br>
would<br>
not be true.<br>
If that type is correct, the problem is that "void delegate() shared"<br>
doesn't parse as a type (there is a workaround because you can create<br>
variables of this type through alias and typeof).<br>
<br>
What, exactly, is wrong here?<br>
</blockquote>
<br>
I think what's wrong is that a shared delegate should implicitly convert<br>
to a non-shared one. The delegate is shared since it can be called<br>
safely from any thread, and making it non-shared only prevent you from<br>
propagating it to more thread so it's not harmful in any way.<br>
<br>
</blockquote>
<br></div></div>
I reported this exact issue already a few months ago and simply didn't get any comment on it. If you really try to use shared to are going to hit more such problems.<br>
<br>
See the shared section of my blogpost: <a href="http://3d.benjamin-thaut.de/?p=18" target="_blank">http://3d.benjamin-thaut.de/?<u></u>p=18</a><br><font color="#888888"><br></font></blockquote><div><br></div><div>Ah, I was looking through the bug reports and didn't see this exact bug. Did I just fail at searching, or should I file it? </div>
</div><br>