*) Fixed an unintentional sign extension during promotion in Java's
[catagits/fcgi2.git] / perl / threaded.PL
CommitLineData
34bfd355 1use Config;
2
3open OUT, ">threaded.fpl";
4print OUT "#!$Config{perlpath}\n";
5print OUT while <DATA>;
6close OUT;
7chmod 0755, "threaded.fpl";
8__END__
9
10use FCGI;
11use Thread;
12
13use constant THREAD_COUNT => 5;
14
15sub doit {
16 my $k = shift;
17 my %env;
18 my $in = do { local *FH };
19 my $out = do { local *FH };
20 my $err = do { local *FH };
21
22 my $request = FCGI::request();
23
24 while ($request->accept(\$in, \$out, \$err, \%env) >= 0) {
25 print $out
26 "Content-type: text/html\r\n",
27 "\r\n",
28 "<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>",
29 "<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>",
30 "Request counts for ", THREAD_COUNT ," threads ",
31 "running on host <i>$env{SERVER_NAME}</i><P><CODE>";
32
33 ++$count[$k];
34
35 {
36 lock(@count);
37 for(my $i = 0; $i < THREAD_COUNT; ++$i) {
38 print $out $count[$i];
39 print $out " ";
40 }
41 }
42 $request->flush();
43 sleep(1);
44 }
45}
46
47for ($t = 1; $t < THREAD_COUNT; ++$t) {
48 new Thread \&doit, $t;
49}
50doit(0);