The first thing you need to fix is this:
lock %{ $cnf{'lock'} };
(Hint: enabling warnings would tell you this!)
You never create a key in %cnf called 'lock'. (And when you do, it would have to contain a reference to a shared variable for that to work.)
Beyond that, there are several pretty dubious pieces of code:
Which almost certainly doesn't do what you think it does, and just serves to confuse things.
Updated in the light of Corion's post below. It seems that END() subs will be treated as END{} blocks...though the sub annotation seems to serve little purpose other than to confused. Making END-blocks compatible with ancient versions of Perl seems to serve little purpose in a program that uses threads.
You appear to think that your sub END will get called automatically (as you never call it directly), but that is not the case.
END{} blocks get called automatically, not subs called END().
# fix me, not work in win32, why? #$SIG{'INT'} = $SIG{'TERM'} = sub { lock %stat; $stat{'done'}++ };
What do you mean by "not work in win32"?
If uncommented, that statement (under win32) does install signal handlers for 'INT' and 'TERM' that do get called. So, in what way "not work"?
# fix me, the thread blocks here, why? # if I lock %{ $cnf{'lock'} } untill close the $c, things +will be OK, # but then we can't gain advantage of the multi-threads no +r the pre-threads # design. if ( my $r = $c->get_request() ) {
It is not at all clear what you mean by that?
To get to that point, this thread has accepted a connection and is now about to fetch the http request that connecting client made. How could it block?
Overall, your post poses no questions. The source code contains several 'fix me' annotations, but the details are terse and sketchy and seem to reflect your misunderstandings more than problem descriptions that can be addressed.
To progress this, you're going to have to detail each of the problems explaining what you think should happen and what actually happens.
You should also explain the format of the urls the clients will send, because expecting us to reverse engineer them from the code is pushing your luck.
In general, dumping a big chunk of code with a few embedded "fix me"s, is not a great way to go about getting help.
In reply to Re: multi thread problem in an simple HTTP server
by BrowserUk
in thread multi thread problem in an simple HTTP server
by bravesoul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |