Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: Prima + MCE::Hobo demonstration

by zentara (Archbishop)
on May 02, 2017 at 13:56 UTC ( [id://1189321]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Prima + MCE::Hobo demonstration
in thread Prima + MCE::Hobo demonstration

Hello mariojoy! I have one question I've been meaning to ask you about MCE::Shared, which setups up some IPC with filehandles passed thru a socketpair? Is this correct? I read in the docs about MCE using IO::FDPass. Can you elaborate on why you pass a filedescriptor, rather than just using the socketpair for communication? Can you elaborate on how this works, and any pitfalls it may have?

I'm not really a human, but I play one on earth. ..... an animated JAPH

Replies are listed 'Best First'.
Re^5: Prima + MCE::Hobo demonstration
by marioroy (Prior) on May 02, 2017 at 15:48 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189321]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found