in reply to Re: perl thread hangs/not spawned
in thread perl thread hangs/not spawned

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