title: Killing child thread in Perl cause death of the parent thread
body: <p>Recently I'm doing a project on Network connections. I'm making the server side program on Perl which handle the request from client, processing, request data from other server. For the multiuser handling purpose I've to use Multitasking. And for not leaking the resource, each thread/connection from client have a limited time out (5 seconds)</p>
  
  <p>Here are my codes:</p>
  
  <pre><code>    while(1)
  {
      # waiting for new client connection.
      $client_socket = $socket-&gt;accept();
      threads-&gt;new(\&amp;gotRequest, $client_socket);
  
      #gotRequest($client_socket);
  
  }
  </code></pre>
  
  <p>This is for Catching the connection from the client</p>
  
  <pre><code>sub gotRequest 
      {
          $client_socket=$_[0];
  #       $peer_address = $client_socket-&gt;peeraddr();
  
          $th1=threads-&gt;new(\&amp;Responce, $client_socket);
          sleep(5);
          if (!($th1-&gt;is_running())) {print "Connection terminated\n";}
          else 
              {
                  print "Operation time out, killing process and terminating connection\n";
                  print $client_socket "QUIT\n";
                  close $client_socket;
                  print "Closing...\n";
  
                  #$thr-&gt;set_thread_exit_only();
                  $th1-&gt;detach();
                  $th1-&gt;exit(); #This thing causing thread's death
  
                  print "Hello I'm still here!";
              }
      }   
  </code></pre>
  
  <p>This is the thread that manage the processing thread to quit on time otherwise server cant get new connection</p>
  
  <pre><code>sub Responce
      {
      $client_socket=$_[0];
      $peer_address = $client_socket-&gt;peeraddr();
      $peer_port = $client_socket-&gt;peerport();
  
      sleep (10);
      print "I'm still alive";
      print "Accepted New Client Connection From : $peeraddress, $peerport\n";#Dont know why but this printed null with 2 null string :(
  
      $client_socket-&gt;recv($data,1024000);
      $data_decode = decode("utf-16", $data);
      print "Received from Client : $data_decode\n";
  
  #Custom code added here
  
      $data = encode("utf-16","DATA from Server");
      print $client_socket "$data\n";
      #close($sock);
      }
  </code></pre>
  
  <p>I got the error:</p>
  
  <pre><code>Thread 1 terminated abnormally: Usage: threads-&gt;exit(status) at server-cotton.pl line 61 thread 1
  </code></pre>
  
  <p>When the </p>
  
  <blockquote>
    <p>$th1->exit();</p>
  </blockquote>
  
  <p>executing.</p>
  
  <p>And one more thing, I can't not disconnect to connection from client.</p>