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?
, , - . . . , , , .
- .
pthreads 0, errno, - .
0
errno
int ret, joined; ret = pthread_create(&thread, NULL, connect, (void*) args); joined = pthread_join(&thread, NULL);
joined , . .
joined
, ( ), pthread_join , , .
pthread_join
, , pthread_join, , pthread_join. IPC, , (TCP-) , , , select, ? pipe , .
select
pipe
, - , : " !". , pthread_join , , , .
, pthread_join , . , , , , , pthread_join , , , - " !" .
IPC , - , - , , .
pthread_cleanup_push(), , , . pthread_key_create() .
pthread_cleanup_push()
pthread_key_create()
pthread_join() - , , pthread_detach().
pthread_join()
pthread_detach()
" , ", , pthread, , - .
? , .
pthread_join . , , .
, , , . , - ( , : volatile), , , - . , listen, , .
volatile
listen
, pthread_join. pthreads . (, , - .)
. ( ), , .
, , , . .
, . ~ 300 Linux , pthread_join . pthread_tryjoin_np. :
, pthread_tryjoin_np POSIX, .
Source: https://habr.com/ru/post/1738064/More articles:Почему ASP.NET может размещать JavaScript в блоках комментариев HTML, а не в CDATA? - javascriptManaged .NET equivalent of CreateFile & WriteFile from WinBase (kernel32.dll) - c ++Property in class IEnumerable get TDto.A == a - c #getResourceAsStream not loading resource - javaUsing URL routing for web forms with .ashx files - c #How important are lifeless sessions? Should web application support support them? - frameworksHow to get all the paths in drupal install - moduleWhat is the easiest way to get the built-in progress bar with Ruby / Sinatra / Haml / Passenger / nginx? - progress-barcan iis 7 be used to manage users when using authentication with asp.net - asp.netNginx update download module with rails and passenger - ruby-on-railsAll Articles