Link to home
Start Free TrialLog in
Avatar of wintch
wintch

asked on

Threads problem

Hello,I'm writing a socket server program with multi-threads. once accept a connect, it will create a thread and process user's request, then exit. but i find thread cannot release handles after it exits from system. In windows NT4.0, when my server process 4000 requests it create 30000 handles, and make system work slowly. what's wrong with my program and how to solve this problem? please help me.

regards

wintch
Avatar of MichaelS
MichaelS

can you sow your code?
Avatar of DanRollins
Why not release the handles before exiting the thread?

-- Dan
ASKER CERTIFIED SOLUTION
Avatar of Paul Maker
Paul Maker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
undefine BROWSER_OUTPUTER
the thread is closed for you automatically

should read

the thread handle is closed for you automatically
You might want to consider implementing a thread pool for this kind of application. You wouldn't want 100 threads running for 100 clients, would you?

You can implement a thread pool by having N threads wait on a queue of actions to perform, or by using a semaphore to limit the number of threads created to service the incoming connection requests.
are you sure you detach from the socket in the main thread prior sending it to the thread for further handling.
1. accept the connection.
2. get the socket handle
3. detach from the socket
4. pass the handle to the thread
5. (in the thread) create a socket using the handle

Hope I'm right - it's been a while
wintch - Date Last Logged In: 08/21/01

You have asked 6 questions and have chosen not to finalize any one of them and award the experts who helped you.  Please return to ALL your open questions to update and finalize them.  I will be posting this in all your open questions and monitoring each of them for completion:

It's time to clean up this topic area and that means taking care of this question. Your options at this point are:
 
1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.
 
2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.
 
3.  Ask Community Support to help split points between participating experts.  Just comment here with details.
 
4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.
 
If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.
 
PLEASE DO NOT AWARD THE POINTS TO ME.
 
____________________________________________
 
 
 
Hi Experts:
 
In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.
 
Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.
 
Thank you everyone.
 
Moondancer :)
Community Support Moderator @ Experts Exchange
 
P.S.  Engineering has been advised about the error in the comment date/time sort order for year 2000 questions, they're in userID order instead.  REGARDING POINTS, Guidelines and more:  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
wintch logged in as recently as 01/29/02 and chose not to update and finalize the open questions, despite
an August request already do to do.  I will post this in them all.

EXPERTS .... please let me know what you believe to be the fair outcome here, since it appears I will be finalizing this if wintch chooses not to within the next 7 days.

Moondancer
Community Support Moderator @ Experts Exchange
Thanks for returning and updating this question.  Can you please tell me why you chose a "B" versus an "A" grade here?  It is always appreciated when grades are less than an A to receive comments as to why so that both experts and future PAQ readers can be advised.

If this was in error, let me know so I can correct this.  The cost to you in terms of points is unchanged, regardless of grade.  However, the expert points earned is increased by a factor of one for each grade level achieved, as noted in the HELP DESK link on the left.

Thank you.

Moondancer
Community Support Moderator @ Experts Exchange