• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Any actor or coroutine implementations for Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any actor or coroutine implementations for Cocoa?


  • Subject: Re: Any actor or coroutine implementations for Cocoa?
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 29 Apr 2008 17:26:17 -0700

I completely derailed my regular project and just worked on coroutines all day. Here's what I've got so far.

* libCoroutine does not build as-is on Mac OS X 10.5. (It's trying to implement its own ucontext API, which then has name collisions with the one that's already in the OS.)

* I tweaked some #ifdefs and got libCoroutine to run, but any nontrivial uses of it crashed hard. Several hours later I tracked this down to what appears to be a bug in the system header <sys/ _structs.h>. Fortunately it was easy to work around. (I've posted a message to the darwin-userlevel mailing list asking about this.)

* Since I was already modifying libCoroutine, and since 90% of its code is just for cross-platform compatibility, I tweezed out just the part that's necessary for Mac OS X and made my own "CoroX.c". It's only 150 lines of code. I can actually read it and understand what it's doing. (I've kept Steve's copyright notice and made it clear this is a derivative work.)

* Then I wrote an Objective-C API around it. Only 140 lines. Here's the header:
http://mooseyard.com/hg/hgwebdir.cgi/Actors/file/tip/Coroutines/MYCoroutine.h


* Finally I put this into a Mercurial repository and hosted it on my website:
http://mooseyard.com/hg/hgwebdir.cgi/Actors/
If you use Mercurial, you can just clone from the above URL to get a local repo. If you don't, you can use the "files" or "zip" links on that web page to browse or download the code.


Next I'd like to implement a simpler "generator" style API (where a coroutine calls "yield" to return a value to its caller) since that's easier for me to get my head around than the general model where every coroutine chooses which one to run next. From there, actors shouldn't be too hard to do.

One potential problem is the interaction with Cocoa features that implicitly rely on the stack: exceptions and autorelease pools. I suspect that coroutines will confuse both of those.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Any actor or coroutine implementations for Cocoa?
      • From: "Michael Ash" <email@hidden>
References: 
 >Any actor or coroutine implementations for Cocoa? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Bug?:? CFPreferencesSynchronize() Remembers Value from Deleted File
  • Next by Date: Re: Modal window and 'hanging' menu
  • Previous by thread: Re: Any actor or coroutine implementations for Cocoa?
  • Next by thread: Re: Any actor or coroutine implementations for Cocoa?
  • Index(es):
    • Date
    • Thread