How do I tell the parent thread that is done using PTHREADS in C?

I have a TCP server application that uses POSIX threads and C to serve each client in the new thread.

The server is in its set Call “listen” on the socket. When the client connects, it will generate a new object of the Client class. The new object runs in its own thread and processes the client’s request.

When the client is disconnected When connecting, I want some way to tell my main() thread that this thread has completed, and main() can delete this object and record something like “Client disconnected”.

My question is , How do I tell the main thread that the thread has completed?

The easiest way I can see is to join the thread. See here. The idea is In the connection call, the command thread will wait for the worker thread to exit and then continue.

Alternatively, you can use some shared variables and mutexes to complete certain operations.

< /div>

I have a TCP server application that uses POSIX threads and C to serve each client in the new thread.

The server is in its socket Call “listen” literally, when the client connects, it will generate a new object of the Client class. The new object runs in its own thread and processes the client’s request.

When the client disconnects When I want some way to tell my main() thread that this thread has completed, and main() can delete this object and record something like “Client disconnected”.

My question is, How do I tell the main thread that the thread has completed?

The easiest way I can see is to join the thread. See here. The idea is that in the connection call, the command thread will wait for the worker thread Exit and continue.

Alternatively, you can use some shared variables and mutexes to complete certain operations.

Leave a Comment

Your email address will not be published.