#!/usr/bin/perl # # Create parent <==> child message relationship with socketpair() # Then thread the parent and try to contact the child use threads; use IPC::MPS; use warnings; use v5.14; my $child; INIT { $child = spawn { receive { msg hi => sub { my ($from) = @_; say "$$ - Hi there!"; snd( $from, 'hi', $$ ); }; }; }; receive { quit; }; say "My child vpid: $child"; } sub say_hi { my $ans = snd_wt( $child, 'hi'); say "$$ - My child $ans said hi"; }; say 'Single-threaded execution'; say_hi; say 'Threaded execution'; my $thr = threads->create( \&say_hi ); $thr->join; __END__ My child vpid: 18275192 Single-threaded execution 7533 - Hi there! 7532 - My child 7533 said hi Threaded execution <_HANGS_HERE_>