#!/usr/bin/perl use strict; use threads; use threads::shared; use IO::Socket; use IO::Select; my ($thr,$tid); my $thrcnt : shared = 0; my $port = 7070; my $socket = IO::Socket::INET->new( LocalPort => $port, Type => SOCK_STREAM, Listen => SOMAXCONN, ReuseAddr => 1 ) or die "Can't create listen socket: $!"; while ((!($tid = threads->tid()))&&(my $client = $socket->accept)) { $thr = threads->create(\&process_request,$client); $tid = threads->tid(); print "main: $tid\n"; $thr->detach; } print "done: exit\m"; ## ## process the request ## sub process_request { my $socket = $_[0]; local %ENV = (); $thrcnt++; my $line = <$socket>; # # #do my thing my $ltid = threads->tid(); print "loop: $thrcnt, $ltid\n"; # # close $socket; }