in reply to What is this "Do you need to predeclare croak" about? [SOLVED]

Hi Karl, I am not clever enough to know how this could lead to the warning, but do you need to use a mutex since you are writing to a shared data structure?

... use MCE::Loop; use MCE::Shared; use MCE::Mutex; my $result = MCE::Shared->hash; my $mutex = MCE::Mutex->new ... mce_loop { my @data = $fetch->($_); sleep AMOUNT; $mutex->enter( $result->set( $_ => \@data ) ); } @urls; ...

Hope this helps! (Mario would know better...)


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: What is this "Do you need to predeclare croak" about?
by marioroy (Prior) on Jun 14, 2017 at 21:55 UTC

    Hi 1nickt. Yes, a mutex is necessary when workers update the same element in a shared hash. For Karl's demonstration, a mutex is optional when workers update unique elements via the OO interface.

      Thanks for clarifying. I hadn't made the distinction, but I see it's an important one, certainly don't want to block if not needed.


      The way forward always starts with a minimal test.
Re^2: What is this "Do you need to predeclare croak" about?
by karlgoethebier (Abbot) on Jun 14, 2017 at 19:20 UTC

    According to Mario i don't need a mutex - as far as i remember ;-)

    Update: I tried it with the mutex as you suggested. Doesn't help.

    Thanks and best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    Furthermore I consider that Donald Trump must be impeached as soon as possible

      Hi! Add next line my script - fix this error for me(Do you need to predeclare croak):

       use IO::Handle;