Are nonblocking I/O operations in Perl limited to one thread? Good design? Are nonblocking I/O operations in Perl limited to one thread? Good design? multithreading multithreading

Are nonblocking I/O operations in Perl limited to one thread? Good design?


Bracketing out your several, larger design questions, I can offer a few approaches to sharing filehandles across perl threads.

One may pass $client to a thread start routine or simply reference it in a new thread:

$client = $server_socket->accept();threads->new(\&handle_client, $client);async { handle_client($client) };# $client will be closed only when all threads' references# to it pass out of scope.

For a Thread::Queue design, one may enqueue() the underlying fd:

$q->enqueue( POSIX::dup(fileno $client) );# we dup(2) so that $client may safely go out of scope,# closing its underlying fd but not the duplicate thereofasync {  my $client = IO::Handle->new_from_fd( $q->dequeue, "r+" );  handle_client($client);};

Or one may just use fds exclusively, and the bit vector form of Perl's select.