2.Perl Multithreading: Threads (thread return value)

Source: Internet
Author: User

1  Usewarnings;2  UseStrict;3  UseThreads;4  5 Subtest{6     Print "Hello, world!\n.";7     return(qw/1 2 3 4 'a'/);8 }9  Ten #return to List Method 1 One my($t 1) = Threads->new ('TEST'); A Print $t 1-Join,"\ n"; -   - #return to list Method 2 the # - my $t 2= Threads->new ({'Context'='List'},'TEST'); - Print $t 2-Join,"\ n"; -   + #returns a single value - my $t 3= Threads->new ('TEST'); + Print $t 3-Join,"\ n"; A getc();

For a function call, if you want to get a return list, you should use a @values to get the return value:

1 #eg.2 my @values= &test;3 #If you return a list in a function call, such as you get the return value with a $value, you should get the value of the last element of the list4 #eg.5 my $value= (1,2,3,4 'a');6 Print $value;7 #result: ' A '8 #注意, this is the same as my $value = 1,2,3,4, ' a ';9 #

In multi-threaded, to get the thread to return the process, then call the Join method, if it is not necessary to get the return value, to call the detach method, if two are not called, you will receive a warning.
In general, you should call the Join/detach method.

2.Perl Multithreading: Threads (thread return value)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.