|
-
Jan 3rd, 2003, 01:19 PM
#1
Thread Starter
Junior Member
How to dispose an object with it's own thread?
I'm currently writing a multithreaded socket server, where each connection has it's own thread. Connections are represented by classes. Upon connection, a new instance in created, which starts a new thread for that connection, and accepts and processes the connection. The reference to the connection is stored in a collection, called colConnections which is maintained by a server class.
So far so good. Now the connection is broken (either by client, server, or from the connection object) and I want to dispose the object. How do I go about? When it needs to be done from the server, it's no problem, but when the client breaks the connection or the connection object breaks the connection I need to get rid of the object.
This might give a better view on the situation.
Code:
server
-- connections
-- connection
So if the "server" closes the connection (like server shutting down), it just gets the object from the "connections" collection, and sets it to nothing.
But when connection is broken by the connection object itself, I need to make sure it is gone completely.
I was thinking of killing the thread that runs the connection object, but I'm not sure if that will do the trick. Will the object itself "disappear" when the thread is gone?
Sorry for the difficult explanation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|