> Date: Tue, 12 Oct 2010 23:46:48 +0100
> From: tim.bu...@pobox.com
> To: faw...@gmail.com
> CC: ben-goldb...@hotmail.com; perl6-language@perl.org
> Subject: Lessons to learn from ithreads (was: threads?)
> 
> On Tue, Oct 12, 2010 at 03:42:00PM +0200, Leon Timmermans wrote:
> > On Mon, Oct 11, 2010 at 12:32 AM, Ben Goldberg <ben-goldb...@hotmail.com> 
> > wrote:
> > > If thread-unsafe subroutines are called, then something like ithreads
> > > might be used.
> > 
> > For the love of $DEITY, let's please not repeat ithreads!
> 
> It's worth remembering that ithreads are far superior to the older
> 5005threads model, where multiple threads ran with an interpreter.
> [Shudder]
> 
> It's also worth remembering that real O/S level threads are needed to
> work asynchronously with third-party libraries that would block.
> Database client libraries that don't offer async support are an
> obvious example.
> 
> I definitely agree that threads should not be the dominant form of
> concurrency, and I'm certainly no fan of working with O/S threads.
> They do, however, have an important role and can't be ignored.
> 
> So I'd like to use this sub-thread to try to identify when lessons we
> can learn from ithreads. My initial thoughts are:
> 
> - Don't clone a live interpreter.
>     Start a new thread with a fresh interpreter.
> 
> - Don't try to share mutable data or data structures.
>     Use message passing and serialization.
> 
> Tim.

If the starting subroutine for a thread is reentrant, then no message passing 
is needed,and the only serialization that might be needed is for the initial 
arguments and for thereturn values (which will be gotten by the main thread via 
join).
As for starting a new thread in a fresh interpreter, I think that it might be 
necessary topopulate that fresh interpreter with (copies of) data which is 
reachable from thesubroutine that the thread calls... reachability can probably 
be identified by usingthe same technique the garbage collector uses.  This 
would provide an effect similar toithreads, but only copying what's really 
needed.
To minimize copying, we would only treat things as reachable when we have to -- 
forexample, if there's no eval-string used a given sub, then the sub only 
"reaches" thosescopes (lexical and global) which it actually uses, not every 
scope that it could use.
                                          

Reply via email to