in reply to Re^4: threads with shared variables across multiple instances of a module
in thread threads with shared variables across multiple instances of a module
This *client{IO}; is invalid syntax when $client is a lexical.
It would have to be *{ $client }{IO}.
But that still won't help you because of an (unnecessary) restriction that doesn't allow you to store globs, (or references to globs) into shared scalars.
There are two ways to share globs (filehandles sockets etc.) between threads:
my %clients :shared; while( my $client = $server->accept; $clients{ client } = fileno( $client ); } ... ## within the threads my $client; my $fileno = $clients{ client }; open $client, "+<&$fileno" or die ... ## dup() the the glob from the f +ileno ## use $client
while( my $client = $server->accept ) { async{ while( my $in = <$client> ) { print $client $in; ### simple echo server } }->detach; }
I've never understood this restriction. The fact that a glob can be successfully shared via the latter method suggests strongly that the restriction both artifical (they just decided to reject glob(ref) assignments to shared scalars--and the code supports this); and unnecessary.
But those that should know the answer to why this restriction was established and persists, have chosen not to answer that question.
|
|---|