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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.