Hi
When using threads, I think we should consider three stages.. 1. create 2. Join 3. detach

create - Creating a new thread
join - Get the values from a already running thread
detach - kill or terminate a running thread


You may refer this tutorial before digging your program..i am going to read first... :)
The following code is working for me.
#!/usr/bin/perl use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use warnings; use threads; my $cgi = new CGI; print $cgi->header(); print <<"endhere"; <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> </head> <body> endhere my $n=threads->create(\&new1); my $m=threads->create(\&new2); sleep(1); my @data1 = $n->join; print @data1 . "\n"; my @data2 = $m->join; print @data2 . "\n"; #$n->detach; #$m->detach; sub new1 { my $i=0; while(1) { print "IIIII $i <br>\n"; $i++; last if($i==25); sleep(1); } } sub new2 { my $i=0; while(1) { print "JJJJJ $i <br>\n"; $i++; last if($i==25); sleep(1); } } print <<"endhere"; </body> </html> endhere


Vivek

In reply to Re: Perl CGI multithreading by viveksnv
in thread Perl CGI multithreading by sathishperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.