Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] gc question: thread stacks, fibers, etc.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Chris Hecker <checker@d...>
Subject: Re: [Caml-list] Coroutines

>I just spent a few hours implementing a small coroutine library.  It
>is fully written in Ocaml.  Below is a quick description.  Would it
>satisfy your needs ? I can send you a copy, or make it available on the
>Web if you like.

Ah, it looks like your library is done with cps.  The problem is, how would 
you yield in the middle of a for-loop or something?  I assume the answer is 
"don't do that" :), which is valid, but a bit frustrating if you just want 
to turn any bit of code into a fiber and be able to yield anywhere it's 
convenient.  On the upside, you can do yours in vanilla caml.  Definitely 
post your library on the web, I'd be interested in seeing it.  Thanks!

I realized after I sent my post about the stack that I can easily prototype 
my Fiber library with Threads.  I'll call what I want Fibers to 
differentiate them from Coroutines where there's value passing a la Knuth, 
and to imply that Fibers are imperative in nature.  I can make a thread per 
fiber, and then have a mutex per thread, and have my yield/switch calls do 
the right mutex silliness to make the threads behave cooperatively rather 
than preemptively.

This is a bit heavyweight for what I want in the systhreads case (I'd like 
Fibers to be very lightweight and cheap, since they don't need any os 
machinery, just a quick context load), but it will allow a fully functional 
(er, operational :) prototype so I can see if this is what I really 
want.  I could ease a bit of the efficiency concerns by adding a thread api 
for turning off the tick thread in the case where no "real" threads are 
created, since mine will never be able to be preempted anyway so setting 
young_limit and the signal is just a waste of time.

Chris


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners