Re: Self-scheduling threading
Re: Self-scheduling threading
- Subject: Re: Self-scheduling threading
- From: Bob Ippolito <email@hidden>
- Date: Thu, 17 Mar 2005 19:47:21 -0500
On Mar 17, 2005, at 7:02 PM, PA wrote:
On Mar 18, 2005, at 00:54, Bob Ippolito wrote:
Coroutines are great and all, but you can't really use them in
normally written Objective-C or C code because they can't use the
stack in the expected manner.
You might find this article of interest:
"Fully Resumable VM"
http://lua-users.org/wiki/ResumableVmPatch
Does that look anything at all like normal C code? No. It all depends
on something very much like continuation passing style, where the only
thing on the stack is the current continuation.
When you're writing VM code, yes, your code will already pretty much
look like this because you've got to pass interpreter state around
(unless your language depends on globals, like Python does -- ugh to
that). However, typical C or Objective-C code does not look anything
at all like it.
I suppose you might be able to worm around some of it by storing the
continuation in thread local storage, but then you still need to invent
a way to put all the necessary labels and gotos in your code, and the
macros to shovel all of your stack locals in and out of it.. etc. etc.
etc. When you're done, it's really not C or Objective-C anymore, it's
some preprocessor macro monstrosity that's probably really difficult to
debug (at runtime or compile time).
To keep this somewhat related to Cocoa, Steve Dekorte wrote a Lua
Objective-C bridge a while back:
"Lua Objective-C"
http://www.dekorte.com/Software/Lua/LuaObjective-C/
There's also PyObjC for Python <http://pyobjc.sf.net/>, which is
actually maintained and is much more complete than any of the other
Objective-C language bridges (probably better than the Java one, too).
You don't get asymmetric coroutines in Python (not without Stackless
anyway), but Python's generators are sufficient to create a pretty
decent cooperative system. And since you have closures, you can at
least do callback based event driven programming in a sane way (i.e.
with Twisted <http://twistedmatrix.com/>). There is even integration
with Twisted and NSRunLoop via PyObjC.
However, that doesn't change the simple fact that C and Objective-C are
terrible at pretending they can do coroutines or anything like them.
So, in other words, you probably shouldn't even bother attempting to
develop an API intended to be used directly from C or Objective-C that
needs coroutines.
-bob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden