I am not using any synchronzation( no queues, no semaphores). And the second thread is spawned after the file is downloaded completely to the web server.

In the main while loop, i do the following

foreach (@connections_pending) { my $fh; my $remote = accept( $fh, $_ ); my ( $port, $iaddr ) = sockaddr_in($remote); my $peeraddress = inet_ntoa($iaddr); my $t = threads->create( \&connection, $fh ); }

So when the request for file upload comes from front0end, i spawn the thread.

Now, in the connection subroutine, i check if its a POST method and if so, i call a subroutine to handle that

sub upload_file { my ( $fh, $req_ ) = @_; my %req = %$req_; my $header_ = $req{HEADER}; my %header = %$header_; my ($file, $desc, $dirpath ) = (undef, undef, undef); my $boundary = trim (form_data_boundary( $header{'content-type'} ) +); my $user_agent = $header{'user-agent'}; # Now i will process the post buffer and copy the file #to local mach +ine into a temp directory. I shall also #receive the filename, destin +ation directory and some #other metadata information. ($file, $desc, $dirpath) = process_POST_buffer($fh, $req_, $boundary); # Then i spawn another thread to do the pre-processing on this file my $t = threads->create( \&pre_process, $file, $desc, $dirpath ); }

The pre-process thread does this

sub pre_process { threads->detach(); my ( $file_name, $desc, $dirpath ) = @_; my ( $file1, $file2, $file3 ) = ( getTempFile(), getTempFile(), + getTempFile() ); my $metadata = i_PreProcessor->new( FILENAME => $file_name, SEARCHXMLFILE => $file1, DESCRIPTION => $desc, MAPXMLFILE => $file2, TAGXMLFILE => $file3, DIRNAME => $dirpath ); $metadata->build2(); #delete temp files. my @files = ( $file1, $file2, $file3 ); unlink(@files); threads->exit(); }
~Arun

In reply to Re^2: perl thread hangs/not spawned by arunb
in thread perl thread hangs/not spawned by arunb

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.