Is there a way to control processes in Perl (i.e., it actually replaces threads)?

I have a multitasking application in perl for which I have to rely on several non-thread safe modules, so I used fork()ed processes with signals kill()as a message passing interface.

The problem is that the signal handlers are a bit messy (at least) and often end up with processes that die in non-directional states.

Is there a better way to do this?

+3
source share
4 answers

forks.pm, " Perl fork()", ( Win32). "" , , ( , thread.pm -).

+4

, , POE, Perl . , - , Perl.

:

  • POE Matt Sergeant ( , , )
  • POE ( )

, POE, .

+7

You can always have a channel between the parent and child to send messages back and forth.

pipe my $reader, my $writer;
my $pid = fork();
if ( $pid == 0 ) {
    close $reader;
    ...
}
else {
    close $writer;
    my $msg_from_child = <$reader>;
    ....
}

Not a very convenient way of programming, but it should not be "unstable".

+6
source

From perl 5.8 onwards, you should look at the main threading module. Take a look at http://metacpan.org/pod/threads

If you want to use modules that are not thread safe, you can usually load them on demand and import them inside the stream entry point.

+1
source

Source: https://habr.com/ru/post/1697567/


All Articles