<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-18241482.post5957964818866041612..comments</id><updated>2009-02-16T10:13:06.736-08:00</updated><title type='text'>Comments on Programming and Debugging (in my Underhøøsen): Nested Functions and Delegates</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://the-free-meme.blogspot.com/feeds/5957964818866041612/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html'/><author><name>The Free Meme</name><uri>http://www.blogger.com/profile/08287129746971472910</uri><email>cristi.vlasceanu@gmail.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-18241482.post-4127884549420414542</id><published>2009-02-16T10:13:00.000-08:00</published><updated>2009-02-16T10:13:00.000-08:00</updated><title type='text'>BCS,I spent more time thinking about the problem t...</title><content type='html'>BCS,&lt;BR/&gt;&lt;BR/&gt;I spent more time thinking about the problem that you outlined.&lt;BR/&gt;&lt;BR/&gt;Over the weekend I had an email exchange with Walter and Bartosz on the topic of threads behavior. &lt;BR/&gt;It turns out that in D 2.0 when a thread is constructed from a delegate, that delegate must have a "shared" modifier (but the specifics of thread creation are not fully baked yet).&lt;BR/&gt;&lt;BR/&gt;I am thinking about using  the "shared" hint and construct the nested function's context in a way that avoids the problem that you so diligently identified. I will post an update when I have a working solution.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default/4127884549420414542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default/4127884549420414542'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html?showComment=1234807980000#c4127884549420414542' title=''/><author><name>The Free Meme</name><uri>http://www.blogger.com/profile/08287129746971472910</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05942387056293398693'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html' ref='tag:blogger.com,1999:blog-18241482.post-5957964818866041612' source='http://www.blogger.com/feeds/18241482/posts/default/5957964818866041612' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-18241482.post-5844391222656375134</id><published>2009-02-12T16:03:00.000-08:00</published><updated>2009-02-12T16:03:00.000-08:00</updated><title type='text'>Thank you for your insight.Your observation is acc...</title><content type='html'>Thank you for your insight.&lt;BR/&gt;&lt;BR/&gt;Your observation is accurate, the delegate (or any nested function for that matter) will not affect the outer scope until the call returns. That's when "the transaction commits".&lt;BR/&gt;&lt;BR/&gt;But I do not see it as incorrect behavior, because I am not aware of any official D specification that governs the observable behavior of multi-threaded programs. &lt;BR/&gt;&lt;BR/&gt;Implementation-dependent behavior is legal (albeit not necessarily fair) game.&lt;BR/&gt;&lt;BR/&gt;I agree a hundred percent that in the case that you described a better design would be for   shared data to reside in an object. &lt;BR/&gt;&lt;BR/&gt;I would never risk having a thread accessing the local variables of some function, betting that it's activation record is valid in another thread (with or without reference counting).</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default/5844391222656375134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default/5844391222656375134'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html?showComment=1234483380000#c5844391222656375134' title=''/><author><name>The Free Meme</name><uri>http://www.blogger.com/profile/08287129746971472910</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05942387056293398693'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html' ref='tag:blogger.com,1999:blog-18241482.post-5957964818866041612' source='http://www.blogger.com/feeds/18241482/posts/default/5957964818866041612' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-18241482.post-7481379535652144223</id><published>2009-02-12T15:32:00.000-08:00</published><updated>2009-02-12T15:32:00.000-08:00</updated><title type='text'>there are several problems with what you describe ...</title><content type='html'>there are several problems with what you describe (assuming I don't understand incorrectly). It sounds like a delegate will not effect the outer function's variable until after it returns to the outer function. what happens in the case that a delegate is called by a called thread or if it is called from another thread. As a pathological case: A thread is launched that calls a delegate that alters a flag in the outer function and then waits for another flag there to be changed. The outer function continues in the old thread an waits on the first flag an then sets the second. Under DMD this would work, but not under your implementation.&lt;BR/&gt;&lt;BR/&gt;I think the correct way to make this work would be to have all variables referred to by nested function only reside in an object. All accesses, by the outer function or nested functions use this object.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default/7481379535652144223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/5957964818866041612/comments/default/7481379535652144223'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html?showComment=1234481520000#c7481379535652144223' title=''/><author><name>BCS</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://the-free-meme.blogspot.com/2009/02/nested-functions-and-delegates.html' ref='tag:blogger.com,1999:blog-18241482.post-5957964818866041612' source='http://www.blogger.com/feeds/18241482/posts/default/5957964818866041612' type='text/html'/></entry></feed>