c++ - Parallel threads stopping each others -
i want application have following behaviour : while application (server) waiting message application (client), want able exit if long input user.
therefore, must launch 2 threads third one:
waitforclientmessage
waitforuserinput
using pthread
, imagined can call each thread , give them id of other, if end, cancel other one. see won't works.
how this? guess simple because such behaviour seen, don't know how work.
edit here general code described imagined.
void main_thread( void) { void * thread_rtn_val; /* parallel threads */ pthread_t thread_waitforclientmessage; pthread_t thread_waitforuserinput; /* run threads */ pthread_create(&thread_waitforclientmessage, null, run_window, (void *)thread_sdp); pthread_create(&thread_waitforuserinput, null, run_client, (void *)arg_array); }
.
void run_window( void) { /* refresh screen , watch user input */ for(...) { if(user press enter) { phtread_cancel(thread_waitforclientmessage) } } }
.
void run_client( void) { /* wait client message */ recv()... phtread_cancel(thread_waitforuserinput) }
have try nonblocking flag function recv() ?
Comments
Post a Comment