<?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: Coroutines, pt. 2</title>
	<atom:link href="http://jens.mooseyard.com/2008/05/coroutines-pt-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/</link>
	<description>Little boxes made of words, by Jens Alfke</description>
	<lastBuildDate>Sun, 14 Mar 2010 11:32:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jens Alfke</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2621</link>
		<dc:creator>Jens Alfke</dc:creator>
		<pubDate>Thu, 08 May 2008 21:04:57 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2621</guid>
		<description>Warren — Thanks for the link! Yes, I&#039;ve heard about protothreads-style designs before; they exploit a weird (ab)use of C switch statements that&#039;s called a &lt;a href=&quot;http://en.wikipedia.org/wiki/Duff%27s_device&quot; rel=&quot;nofollow&quot;&gt;&quot;Duff&#039;s Device&quot;&lt;/a&gt;.

The problem with these is that none of the local variables in your functions are preserved across context switches! It&#039;s really just using a &#039;goto&#039; to jump back into the middle of the function when control returns. They&#039;re definitely as light-weight as you can get, but I&#039;ll bet they&#039;re very hard to program for.</description>
		<content:encoded><![CDATA[<p>Warren — Thanks for the link! Yes, I&#8217;ve heard about protothreads-style designs before; they exploit a weird (ab)use of C switch statements that&#8217;s called a <a href="http://en.wikipedia.org/wiki/Duff%27s_device" rel="nofollow">&#8220;Duff&#8217;s Device&#8221;</a>.</p>
<p>The problem with these is that none of the local variables in your functions are preserved across context switches! It&#8217;s really just using a &#8216;goto&#8217; to jump back into the middle of the function when control returns. They&#8217;re definitely as light-weight as you can get, but I&#8217;ll bet they&#8217;re very hard to program for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: http://warrenharris.myopenid.com/</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2620</link>
		<dc:creator>http://warrenharris.myopenid.com/</dc:creator>
		<pubDate>Thu, 08 May 2008 17:27:09 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2620</guid>
		<description>Eigenclass had a good survey recently of lightweight threads packages: http://eigenclass.org/hiki/threadring-with-protothreads</description>
		<content:encoded><![CDATA[<p>Eigenclass had a good survey recently of lightweight threads packages: <a href="http://eigenclass.org/hiki/threadring-with-protothreads" rel="nofollow">http://eigenclass.org/hiki/threadring-with-protothreads</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jens Alfke</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2619</link>
		<dc:creator>Jens Alfke</dc:creator>
		<pubDate>Sun, 04 May 2008 15:21:49 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2619</guid>
		<description>E.Wing — Yes, I&#039;ve been interested in Lua &lt;a href=&quot;http://mooseyard.com/Jens/2005/06/lua-and-unique-strings/&quot; rel=&quot;nofollow&quot;&gt;for a while&lt;/a&gt;. In the PubSub framework we used Lua as the templating engine for converting news articles into HTML pages for Safari RSS to display.

I don&#039;t believe Lua&#039;s coroutines affect the native (C) execution context, though. They just switch Lua&#039;s interpreted stack around. So calling back into native code from a Lua coroutine wouldn&#039;t be anything like using native coroutines.</description>
		<content:encoded><![CDATA[<p>E.Wing — Yes, I&#8217;ve been interested in Lua <a href="http://mooseyard.com/Jens/2005/06/lua-and-unique-strings/" rel="nofollow">for a while</a>. In the PubSub framework we used Lua as the templating engine for converting news articles into HTML pages for Safari RSS to display.</p>
<p>I don&#8217;t believe Lua&#8217;s coroutines affect the native (C) execution context, though. They just switch Lua&#8217;s interpreted stack around. So calling back into native code from a Lua coroutine wouldn&#8217;t be anything like using native coroutines.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: E. Wing</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2618</link>
		<dc:creator>E. Wing</dc:creator>
		<pubDate>Sun, 04 May 2008 10:40:28 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2618</guid>
		<description>Probably not quite what you were thinking, but have you looked at Lua? Coroutines were added in Lua 5. Lua is written in 100% ANSI C, so it&#039;s extremely portable. Since Lua&#039;s strength is as an embedded language, you could consider factoring your code such that you invoke Lua to take the responsibility of directly creating/managing coroutines, and then have each coroutine call back into Obj-C to do your real work.

Chapter 9 of the Programming in Lua Book (version 5.0 free online) covers different examples of using coroutines in Lua.</description>
		<content:encoded><![CDATA[<p>Probably not quite what you were thinking, but have you looked at Lua? Coroutines were added in Lua 5. Lua is written in 100% ANSI C, so it&#8217;s extremely portable. Since Lua&#8217;s strength is as an embedded language, you could consider factoring your code such that you invoke Lua to take the responsibility of directly creating/managing coroutines, and then have each coroutine call back into Obj-C to do your real work.</p>
<p>Chapter 9 of the Programming in Lua Book (version 5.0 free online) covers different examples of using coroutines in Lua.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wim Leers</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2617</link>
		<dc:creator>Wim Leers</dc:creator>
		<pubDate>Sun, 04 May 2008 07:17:03 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2617</guid>
		<description>We&#039;ve had to implement our own super light-weight threading library (just cooperative of course, through a &quot;yield&quot; call) by using ucontext as a university assignment. Cool to see that the pros really are doing this kind of stuff as well :)

Anyway, I don&#039;t remember the details, but I do remember that pthreads has a significant overhead when compared to ucontext.</description>
		<content:encoded><![CDATA[<p>We&#8217;ve had to implement our own super light-weight threading library (just cooperative of course, through a &#8220;yield&#8221; call) by using ucontext as a university assignment. Cool to see that the pros really are doing this kind of stuff as well :)</p>
<p>Anyway, I don&#8217;t remember the details, but I do remember that pthreads has a significant overhead when compared to ucontext.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Roberts</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2616</link>
		<dc:creator>Sam Roberts</dc:creator>
		<pubDate>Sat, 03 May 2008 17:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2616</guid>
		<description>I think pthreads have a lot more overhead than ucontext. You might not be interested in huge numbers of co-routines, but when you create a thread you get its /proc entries, it gets references to all the file descriptors, preemptive context switching might occur during floating point operations, which forces saving the FPU state. From a pure size, do a sizeof(uncontext_t) and then imagine all the places in the kernel that know about your threads... Also, the kernel tracks use/system space execution time for threads.

That said, it hard to imagine coros NOT wreaking havoc on the obj-c runtime!</description>
		<content:encoded><![CDATA[<p>I think pthreads have a lot more overhead than ucontext. You might not be interested in huge numbers of co-routines, but when you create a thread you get its /proc entries, it gets references to all the file descriptors, preemptive context switching might occur during floating point operations, which forces saving the FPU state. From a pure size, do a sizeof(uncontext_t) and then imagine all the places in the kernel that know about your threads&#8230; Also, the kernel tracks use/system space execution time for threads.</p>
<p>That said, it hard to imagine coros NOT wreaking havoc on the obj-c runtime!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jens Alfke</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2614</link>
		<dc:creator>Jens Alfke</dc:creator>
		<pubDate>Sat, 03 May 2008 17:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2614</guid>
		<description>Oho! I had been thinking about using a lock per thread, but your idea of a numeric ID on a single lock is very clever. Thanks!

(And yeah, probably no need to use pthreads API if I can do it with Foundation classes.)</description>
		<content:encoded><![CDATA[<p>Oho! I had been thinking about using a lock per thread, but your idea of a numeric ID on a single lock is very clever. Thanks!</p>
<p>(And yeah, probably no need to use pthreads API if I can do it with Foundation classes.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jens Ayton</title>
		<link>http://jens.mooseyard.com/2008/05/coroutines-pt-2/comment-page-1/#comment-2615</link>
		<dc:creator>Jens Ayton</dc:creator>
		<pubDate>Sat, 03 May 2008 16:57:02 +0000</pubDate>
		<guid isPermaLink="false">http://mooseyard.com/Jens/2008/05/coroutines-pt-2/#comment-2615</guid>
		<description>I believe the shared lock technique is also used for Thread Manager threads under OS X, for non-tutorial purposes.

At the Cocoa level, what you’re asking could be done with a condition lock. Each task would be given a numeric ID, and use that as a condition for -lockWhenCondition:. Yielding to a specific routine would be implemented on -unlockWithCondition:, and round-robin scheduling could be easily built on top of that.

I assume there’s a pthread-level equivalent to NSConditionLock, but I haven’t looked.</description>
		<content:encoded><![CDATA[<p>I believe the shared lock technique is also used for Thread Manager threads under OS X, for non-tutorial purposes.</p>
<p>At the Cocoa level, what you’re asking could be done with a condition lock. Each task would be given a numeric ID, and use that as a condition for -lockWhenCondition:. Yielding to a specific routine would be implemented on -unlockWithCondition:, and round-robin scheduling could be easily built on top of that.</p>
<p>I assume there’s a pthread-level equivalent to NSConditionLock, but I haven’t looked.</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! -->