in reply to Re: Why won't this Deadlock?
in thread Why won't this Deadlock?

Hi Mario,

I'm going on vacation soon, so I'll print on the manuals to MCE::* and try to comment on how this research compares.

DESCRIPTION A Hobo is a migratory worker inside the machine that carries the asynchronous gene. Hobos are equipped with "threads"-like capability for running code asynchronously. Unlike threads, each hobo is a unique process to the underlying OS. The IPC is managed by "MCE::Shared", which runs on all the major platforms including Cygwin.
It seems you are way ahead of me in thinking about this. That's a cool venture (MCE::*); I see tonnes of applications for it.

I appreciate the diff. Thank-you.

Do you have terminology for the scope of data shared between processes?

So PIE in the sky question is...

How would I have a data shared for the lifetime of a block, and I want that block to run first, amongst all the processes that share it?

{ use MCE::Shared; my $cnt; #tie my $cnt, 'MCE::Shared', { module => 'MCE::Shared::Scalar' }, 0; tie my $va1, 'MCE::Shared', { module => 'MCE::Shared::Scalar' }, sub { + return $cnt++; }; #just for fun let's make a closure # How can I be sure that ($val->() == 0)? say ($val->()) ? 0 : 1; # says 1 if first caller }
My Brain is saying that setting a mutex to protect the call to $val would be a recursive solution with no end? Eg. No atomic-ity, eg deadlock. Yeah, if it was synchronous it would work, but it's not.

I said deadlock is on the horizon because the block could be wrapped in another block with a different mutex controlling the lower one. Got to run to an appointment. I'm going to be late. All the best, Jambo

Replies are listed 'Best First'.
Re^3: Why won't this Deadlock?
by marioroy (Prior) on Jul 11, 2017 at 16:33 UTC

    Hi Jambo Hamon,

    Enjoy your vacation. When you come back, I'd likely have MCE 1.830 (bug fixes) and MCE::Shared 1.827 released on CPAN. The OO interface for shared objects makes it possible to not worry about mutex at the application level.

    use MCE::Shared; my $val = MCE::Shared->scalar(0); $val->incr(); $val->incrby(20); $val->set(40); my @pairs = ('aa'..'zz'); my $oh = MCE::Shared->ordhash(); my $ha = MCE::Shared->hash(); $oh->assign( @pairs ); $ha->assign( @pairs ); $ha->set( counter => 0 ); $ha->incr('counter'); $ha->incrby('counter', 2); my $val = $ha->get('counter'); # Scoping works similarly to lexical scoping in Perl. # The shared object is destroyed upon leaving the scope. { my $ar = MCE::Shared->array(1..9); $ar->assign('aa'..'zz'); }

    Passing a code reference via IPC isn't supported at this time. Perhaps, I can add filter support for STORE (set), FETCH (get) at a later time. I'm currently at a code freeze with MCE 1.830 and MCE::Shared 1.827.

    use MCE::Shared; my $obj = MCE::Shared->scalar(0); $obj->filter_store_value( \&code ); $obj->filter_fetch_value( \&code );

    Regards, Mario