<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Active Sleep procedure</title>
	<atom:link href="http://www.cromis.net/blog/2008/11/active-sleep-procedure/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cromis.net/blog/2008/11/active-sleep-procedure/</link>
	<description>A blog about Delphi programming and all things technical</description>
	<lastBuildDate>Tue, 16 Mar 2010 11:51:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: gabr</title>
		<link>http://www.cromis.net/blog/2008/11/active-sleep-procedure/comment-page-1/#comment-9</link>
		<dc:creator>gabr</dc:creator>
		<pubDate>Thu, 27 Nov 2008 04:56:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.cromis.net/blog/?p=181#comment-9</guid>
		<description>Your approach is sound, but you can run into reentrancy problems - your ActiveSleep is processing messages which mean that you have to correctly process everything while your thread is &quot;blocked&quot; and that means that you have to be careful, not to call any code that will interfere with the current execution. The problem is equivalent to calling Application.ProcessMessages from the event handler - it will work but you can run into problems quite fast.

My first idea would be to run &quot;blocked&quot; code in the &#039;parent&#039; thread (as you name it). If the thread should block during the execution, you can just run the processing part in that thread. Of course, this may cause problems because you would not be processing messages during that time ...

I dislike this approach and I&#039;m not using it in my code. I think it is much better to do even &#039;blocking&#039; processing asynchronously. Just mark that the &#039;blocking&#039; code is being executed somewhere and don&#039;t schedule any new requests until this flag is cleared. Insted of executing, store them in some waiting queue. When &#039;blocking&#039; code completes, start scheduling requests that are waiting in the queue (until you run out of requests or you encounter another &#039;blocking&#039; request).</description>
		<content:encoded><![CDATA[<p>Your approach is sound, but you can run into reentrancy problems &#8211; your ActiveSleep is processing messages which mean that you have to correctly process everything while your thread is &#8220;blocked&#8221; and that means that you have to be careful, not to call any code that will interfere with the current execution. The problem is equivalent to calling Application.ProcessMessages from the event handler &#8211; it will work but you can run into problems quite fast.</p>
<p>My first idea would be to run &#8220;blocked&#8221; code in the &#8216;parent&#8217; thread (as you name it). If the thread should block during the execution, you can just run the processing part in that thread. Of course, this may cause problems because you would not be processing messages during that time &#8230;</p>
<p>I dislike this approach and I&#8217;m not using it in my code. I think it is much better to do even &#8216;blocking&#8217; processing asynchronously. Just mark that the &#8216;blocking&#8217; code is being executed somewhere and don&#8217;t schedule any new requests until this flag is cleared. Insted of executing, store them in some waiting queue. When &#8216;blocking&#8217; code completes, start scheduling requests that are waiting in the queue (until you run out of requests or you encounter another &#8216;blocking&#8217; request).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->