How to tell parents that a thread is running in C ++ using pthreads?

I have a TCP Server application that serves every client in a new thread using POSIX and C ++ streams.

The server calls a listen on its socket, and when the client connects, it creates a new object of the Client class. The new object runs in its stream and processes client requests.

When the client disconnects, I want some way to tell my main () thread that this thread has completed, and main () can delete this object and write something like "The client is disconnected."

My question is: how can I tell the main thread that the thread is running?

+3
source share
8 answers

, , - . . . , , , .

- .

+2

pthreads 0, errno, - .

int ret, joined;
ret = pthread_create(&thread, NULL, connect, (void*) args);
joined = pthread_join(&thread, NULL);

joined , . .

+2

, ( ), pthread_join , , .

, , pthread_join, , pthread_join. IPC, , (TCP-) , , , select, ? pipe , .

, - , : " !". , pthread_join , , , .

, pthread_join , . , , , , , pthread_join , , , - " !" .

+2

IPC , - , - , , .

pthread_cleanup_push(), , , . pthread_key_create() .

pthread_join() - , , pthread_detach().

+1

" , ", , pthread, , - .

? , .

0

pthread_join . , , .

, , , . , - ( , : volatile), , , - . , listen, , .

0

, pthread_join. pthreads . (, , - .)

. ( ), , .

, , , . .

0

, . ~ 300 Linux , pthread_join . pthread_tryjoin_np. :

  • ,
  • . pthread_tryjoin_np , . , , , . pthread_tryjoin_np . pthread_tryjoin_np , 0, , , .

, pthread_tryjoin_np POSIX, .

0

Source: https://habr.com/ru/post/1738064/


All Articles