On Thu, Sep 20, 2001 at 12:33:54PM -0700, Hong Zhang wrote:
>
> > DS> I'm also seriously considering throwing *all* PerlIO code into
> > separate
> > DS> threads (one per file) as an aid to asynchrony.
> >
> > but that will be hard to support on systems without threads. i still
> > have that internals async i/o idea floating in my numb skull. it is an
> > api that would look async on all platforms and will use the kernel async
> > file i/o if possible. it could be made thread specific easily as my idea
> > was that the event system was also thread specific.
>
> I think we should have some thread abstraction layer instead of throwing
> PerlIO into threads. The thread
> abstraction layer can use either native thread package (blocking io), or
> implement user level thread package
> with either non-blocking io or async io. The internal io should be sync
> instead of async. async is normally
> slower than sync (most of unix don't have real async io), and thread is
> cheap.
I agree. Threads, at least in spirit, provide a cleaner interface to
threading and asynchronous I/O than user level callbacks. There's
nothing stopping a compiler from generating event driven code out of
procedural, perhaps even threaded code. Consider this:
sub read_console {
print while (<>);
}
sub read_log {
print while (<LOG>);
}
Thread->new( \&read_console );
Thread->new( \&read_log );
sleep 1 while threads_active();
exit 0;
A compiler can either generate threaded code that's pretty close to
the original source, or it can generate asynchronous callbacks at the
bytecode level. The same source code could compile and run on systems
that support asynchronous I/O, threads, or both.
Here's some parrot assembly that may or may not be legal at the
moment. It shows what a compiler might do with the threaded source
code on a system that only supported asynchronous I/O.
read_console_entry:
find_global P1, "STDIN", "main"
set I1, read_console_got_line
jsr set_input_callback
return
read_console_got_line:
# Assumes the AIO engine sets S1 with a read line.
print S1
return
read_log_entry:
find_global P1, "LOG", "main"
set I1, read_log_got_line
jsr set_input_callback
return
read_log_got_line:
# Assumes the AIO engine sets S1 with a read line.
print S1
return
main:
set I1, read_console_entry
jsr thread_new
set I1, read_log_entry
jsr thread_new
main_timer_loop:
set I1, main_timer_done
set I2, 1
jsr set_timer
return
main_timer_done:
jsr threads_active
ne I1, 0, main_timer_loop
end
__END__
-- Rocco Caputo / [EMAIL PROTECTED] / poe.eekeek.org / poe.sourceforge.net