Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Update: Made a fork so not having to apply the diff by hand if wanting to try https://github.com/marioroy/pm-cb. The only benefit to using MCE::Child and MCE::Channel is that there is one less process on Unix platforms (i.e. no shared-manager process). choroba, please know that it is okay to reject this. I made a fork simply to test pm-cb-g using MCE::Child and MCE::Channel for my own validation.

Hi,

I released MCE 1.841 (includes MCE::Channel and MCE::Child) and MCE::Shared 1.841. During development, ran pm-cb-g using MCE::Child and MCE::Channel on my laptop (macOS) including a Windows 7 VM. Here is the diff output (long form).

diff -aur pm-cb-master/lib/PM/CB/Control.pm pm-cb-master2/lib/PM/CB/Co +ntrol.pm --- pm-cb-master/lib/PM/CB/Control.pm 2019-06-08 16:07:06.000000000 + -0400 +++ pm-cb-master2/lib/PM/CB/Control.pm 2019-07-10 22:40:18.00000000 +0 -0400 @@ -15,6 +15,9 @@ sub start_comm { my ($self) = @_; $self->{communicate_t} = $self->{worker_class}->create(sub { + if ($INC{'threads.pm'}) { + $SIG{QUIT} = sub { threads->exit }; + } my $communication = PM::CB::Communication->new({ to_gui => $self->{to_gui}, from_gui => $self->{to_comm}, @@ -42,9 +45,11 @@ $self->{to_comm}->enqueue(['url']); }; } - $self->{to_comm}->insert(0, ['quit']); - $self->{communicate_t}->join; - $self->{to_gui}->insert(0, ['quit']); + if ($^O ne 'MSWin32' || ! $INC{'MCE/Util.pm'}) { + $self->{communicate_t}->kill('QUIT'); + $self->{communicate_t}->join; + } + $self->{to_gui}->enqueue(['quit']); } diff -aur pm-cb-master/lib/PM/CB/GUI.pm pm-cb-master2/lib/PM/CB/GUI.pm --- pm-cb-master/lib/PM/CB/GUI.pm 2019-06-08 16:07:06.000000000 -04 +00 +++ pm-cb-master2/lib/PM/CB/GUI.pm 2019-07-06 15:17:07.000000000 -0 +400 @@ -673,7 +673,7 @@ sub quit { my ($self) = @_; print STDERR "Quitting...\n"; - $self->{to_control}->insert(0, ['quit']); + $self->{to_control}->enqueue(['quit']); } diff -aur pm-cb-master/pm-cb-g pm-cb-master2/pm-cb-g --- pm-cb-master/pm-cb-g 2019-06-08 16:07:06.000000000 -0400 +++ pm-cb-master2/pm-cb-g 2019-07-06 15:11:58.000000000 -0400 @@ -55,15 +55,15 @@ } -use if $mce => 'MCE::Hobo'; -use if $mce => 'MCE::Shared'; +use if $mce => 'MCE::Child'; +use if $mce => 'MCE::Channel'; use if ! $mce => threads => (stack_size => 2 ** $stack_size); use if ! $mce => 'Thread::Queue'; my ($queue_class, $queue_constructor, $worker_class) = $mce - ? ('MCE::Shared', 'queue', 'MCE::Hobo') + ? ('MCE::Channel', 'new', 'MCE::Child') : ('Thread::Queue', 'new', 'threads'); my ($to_gui, $to_comm, $to_control)

The ->insert method is lacking in MCE::Channel due to an edge case so not implemented. Signaling workers is another way and works well using threads on Windows, MCE::Hobo or MCE::Child on Unix. Threads requires one to define the signal handler whereas MCE::Hobo and MCE::Child already configure $SIG{QUIT} to terminate.

Update: I needed to enclose two lines above inside an if statement due to signal handling delayed for child processes (emulated) on the Windows platform. Perhaps the Tk loop is preventlng signaling from happening, am not sure. Tested the update on macOS and WIndows with and without the -m command-line switch.

+ if ( $^O ne 'MSWin32' || ! $INC{'MCE/Child.pm'} ) { + $self->{communicate_t}->kill('QUIT'); + $self->{communicate_t}->join; + }

Q. Why does MCE::Channel lack the insert method?

A. Unlike MCE::Shared->queue, there is no manager process involvement in MCE::Channel. Thus, a worker holding a read lock on an empty channel (awaiting next item) makes it impossible for another worker inserting. Enqueue involves write lock only, but insert requires both read and write locks.

Regards, Mario


In reply to Re^4: A new CB reader by marioroy
in thread A new CB reader by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found