[MacRuby-devel] Fibers and Enumerators

easco easco at mac.com
Fri Aug 13 13:11:29 PDT 2010


I said:
>> (i.e. Mac OS X doesn't really have any built-in support for cooperatively scheduled multitasking... outside of 
>> deprecated technologies like the Carbon Thread Manager and makecontext/swapcontext). 

Dr. Prabhakar said:

Actually, I'm confused by that statement. My understanding is that cooperatively scheduled threads is a just a subset of the system-scheduled model.

In particular, I'm pretty sure you can emulate them on top of GCD using semaphores. Should I explain further, or did you already consider that and discover it was unworkable?
 
You're right it is a very poorly worded statement and a convoluted mess conceptually. 

I do understand that you can emulate cooperative multitasking using threads and semaphores. I didn't really reject it as unworkable  I rejected it because it wasn't the solution I was looking for. :-)

I am working under the impression that pthreads are a "heavy-weight" construct (an impression bolstered by watching too many GCD sessions, I imagine). By that I mean each pthread consumes kernel resources, scheduler attention, etc. In contrast a Fiber is a comparitively light-weight construct.  Each fiber has a distinct execution context, but they don't require the direct attention of the system scheduler.  The run inside the context of the kernel level thread.

One aspect of my confusing statement is meant to convey that I could not find this intra-thead multitasking concept already implemented in Mac OS X, nor could I find primitives like makecontext and swapcontext upon which it could be built easily.

The other idea I meant to convey is that I also cannot find an API whose syntax directly supports the concept of cooperatively scheduled threads of execution. The Carbon Thread Manager presents such an API. The API itself reflects the model of cooperative threads of execution, yielding between them, etc.

As you point out, you can emulate the cooperative model using the various threading APIs using threads and synchronization primitives. Doing so allows you to implement the semantic of that model.  My point, however, is that if you want a nice syntax that expresses the cooperative model you're going to have to do the plumbing yourself, and add your own façade. The OS no longer provides one.

Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100813/91d5802c/attachment.html>


More information about the MacRuby-devel mailing list