I'm building 2 programs (client/server) that communicate through FIFOs. Both programs have threads. When the Client's thread ends it doesn't get joined, and main hangs.
The programs do the following:
Server:
- main: reads from FIFO1
- main: create thread to process request.
- main: goto 1
- thread: processes request
- thread: sends response to FIFO2
- thread: exit
Client:
- main: spawn thread
- thread: reads X responses to client from FIFO2
- thread: exit
- main: sends X requests to FIFO1
- main: wait thread to exit
- main: check responses
The server works well and all threads are joined accordingly.
The client fails in step 5. Using
pthread_join(&reader,NULL);
hangs main forever. I've checked, and the thread already ended.
Using
pthread_tryjoin_np(&reader,NULL);
I get
errorcode=16
strerror gives
Device or resource busy
Creating the thread with:
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
pthread_create(&reader,&attr,trataResp,NULL);
Or with: pthread_create(&reader,NULL,trataResp,NULL);
doesn't produce any change.
How can I resolve this?
Well pthread_join receives the thread id, not the address for it. This line:
Should be:
If
reader
was declared aspthread_t
.Hope it's not just a typo in your question and that this actually helps.