in reply to Re^4: Prima + MCE::Hobo demonstration
in thread Prima + MCE::Hobo demonstration
Hi zentara,
For MCE::Shared, the use of IO::FDPass applies to Condvar, Queue and to mce_open when constructing a shared handle from a non-shared handle not yet knowed to the shared-manager process. IO::FDpass isn't used for anything else.
use MCE::Shared; # starting the shared-manager, implicitly my $ca = MCE::Shared->cache( max_keys => 500 ); # or starting early, explicitly MCE::Shared->start(); # at this point, IO::FDPass is necessary for constructing # a shared condvar or queue, passing fd descriptor # ... for new socket handle made during construction # workers block using a socket handle for ->wait, ->timedwait # the shared-manager unblocks by writing to _cw_sock my $cv = MCE::Shared->condvar(); # _cw_sock # ... for new socket handles made during construction # workers block using socket handles for ->dequeue, ->await # the shared-manager unblocks by writing to _qw_sock, _aw_sock my $q1 = MCE::Shared->queue(); # _qw_sock my $q2 = MCE::Shared->queue( await => 1 ); # _aw_sock
Without IO::FDPass, one cannot construct a shared condvar or queue while the shared manager is running. The work around is to construct these before other shared objects (e.g. ->array, ->hash, etc). Then, start the shared-manager manually.
use MCE::Shared; my $cv = MCE::Shared->condvar(0); my $que = MCE::Shared->queue( fast => 1 ); MCE::Shared->start() # must start manually my $hash = MCE::Shared->hash(); # or implicitly
Note: MCE starts the shared-manager if not started. Ditto for MCE::Hobo because that constructs two shared hashes.
Regarding mce_open, IO::FDPass is needed when constructing a shared-handle from a non-shared handle not yet available inside the shared-manager process. The workaround is having the non-shared handle made before the shared-manager process is started implicitly or explicitly.
# the shared-manager knows of \*STDIN, \*STDOUT, \*STDERR mce_open my $shared_in, "<", \*STDIN; # ok mce_open my $shared_out, ">>", \*STDOUT; # ok mce_open my $shared_err, ">>", \*STDERR; # ok # but may not know of $non_shared_fh mce_open my $shared_fh, ">>", $non_shared_fh;
Regards, Mario
|
---|