<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>程式設計 遇上 小提琴 &#187; deadlock</title>
	<atom:link href="http://blog.ez2learn.com/tag/deadlock/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ez2learn.com</link>
	<description>Victor&#039;s個人部落格，關於程式設計與小提琴</description>
	<lastBuildDate>Tue, 07 Feb 2012 03:26:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>第一次遇到Deadlock</title>
		<link>http://blog.ez2learn.com/2009/02/10/the-first-deadlock/</link>
		<comments>http://blog.ez2learn.com/2009/02/10/the-first-deadlock/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 04:36:36 +0000</pubDate>
		<dc:creator>victor</dc:creator>
				<category><![CDATA[中文文章]]></category>
		<category><![CDATA[英文]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[multi-threading]]></category>

		<guid isPermaLink="false">http://blog.ez2learn.com/?p=529</guid>
		<description><![CDATA[凡事都要來個第一次，這兩天遇到一個deadlock，是我第一次遇到deadlock，其實很多deadlock都很明顯可以避免掉，但有些就不明顯，這次遇到的deadlock，是因為正在開發一個DirectShow的應用程式，我使用Python把核心部份寫好包裝成Extension給Python使用來加速開發，不然每次光等編譯就等到睡著 我使用DirectShow 的 Sample Grabber filter來抓取從DirectShow播放出來的音樂，DirectShow的graph會建立一個thread來處理事情，而它使用一個callback來回傳資料，好死不死，我的程式從Python的程式碼的Main thread呼叫graph的stop，但是stop似乎會等callback回傳，再來又好死不死的，callback因為要把資料丟回Python，要求Python的GIL，所謂的GIL就是Python直譯器的lock，整個Python行程只有一個，所以就變成下列情況 Main thread (hold GIL) -&#62; call stop(Wait for callback) -&#62; Callback acquire GIL -&#62; GIL&#8230;.(Hold by main thread) 囧&#8230; 這幾個笨蛋(設計的人比較笨)，就這樣一直癡癡地等下去，等到天荒地老都沒有人會理他們，這真是悲慘&#8230;.，所以在寫multi-threading的程式時一定要特別小心，明顯的deadlock當然是很容易避免，但是像這種文件上沒說清楚，隱涵著lock，又繞了一圈的情況，就很難一開始想到]]></description>
			<content:encoded><![CDATA[<p>凡事都要來個第一次，這兩天遇到一個deadlock，是我第一次遇到deadlock，其實很多deadlock都很明顯可以避免掉，但有些就不明顯，這次遇到的deadlock，是因為正在開發一個DirectShow的應用程式，我使用Python把核心部份寫好包裝成Extension給Python使用來加速開發，不然每次光等編譯就等到睡著</p>
<p>我使用DirectShow 的 Sample Grabber filter來抓取從DirectShow播放出來的音樂，DirectShow的graph會建立一個thread來處理事情，而它使用一個callback來回傳資料，好死不死，我的程式從Python的程式碼的Main thread呼叫graph的stop，但是stop似乎會等callback回傳，再來又好死不死的，callback因為要把資料丟回Python，要求Python的GIL，所謂的GIL就是Python直譯器的lock，整個Python行程只有一個，所以就變成下列情況</p>
<p>Main thread (hold GIL) -&gt; call stop(Wait for callback) -&gt; Callback acquire GIL -&gt; GIL&#8230;.(Hold by main thread)</p>
<p>囧&#8230;</p>
<p>這幾個笨蛋(設計的人比較笨)，就這樣一直癡癡地等下去，等到天荒地老都沒有人會理他們，這真是悲慘&#8230;.，所以在寫multi-threading的程式時一定要特別小心，明顯的deadlock當然是很容易避免，但是像這種文件上沒說清楚，隱涵著lock，又繞了一圈的情況，就很難一開始想到</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ez2learn.com/2009/02/10/the-first-deadlock/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

