File: check_perlthreading.pl

package info (click to toggle)
torrus 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,740 kB
  • ctags: 707
  • sloc: perl: 25,904; xml: 16,400; sh: 3,788; makefile: 603
file content (37 lines) | stat: -rw-r--r-- 609 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

use threads;

$| = 1;

print "The child thread must keep ticking while the main thread sleeps\n";
print "If it's not so, then we have a compatibility problem\n";



my $thrChild = threads->create( \&child );
$thrChild->detach();

print "P> Launched the child thread. Now I sleep 20 seconds\n";
sleep(20);
print "P> Parent woke up. Was there ticking inbetween?\n";

exit 0;



sub child
{
    print "C> Child thread started. I will print 10 lines, one per second\n";

    foreach my $i (1..10)
    {
        print("C> Child tick " . $i . "\n");
        sleep(1);
    }
}