C pthread joins the completed thread

I am building 2 programs (client / server) that communicate through FIFO. Both programs have threads. When the client thread ends, it does not connect, but main hangs.

Programs perform the following actions:

Server:

  • main: read from FIFO1
  • main: create a thread to request the process.
  • main: goto 1
  • thread: process request
  • stream: sends a response to FIFO2
  • stream: output

Customer:

  • main: spwn thread
  • thread: reads X responses to a client from FIFO2
  • stream: output
  • main: sends X requests to FIFO1
  • main: wait thread to exit
  • main: check answers

The server works well, and all threads are connected accordingly.

The client does not work in step 5. Using

pthread_join(&reader,NULL);

hanging forever. I checked and the stream is already over.

Using

pthread_tryjoin_np(&reader,NULL);

I get

errorcode = 16

strerror gives

Waiting for a device or resource

Creating a stream with

pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
pthread_create(&reader,&attr,trataResp,NULL);

:   pthread_create (& , NULL, trataResp, NULL);

.

?

+3
1

pthread_join , . :

pthread_join(&reader,NULL);

:

pthread_join(reader,NULL);

reader pthread_t.

, .

+4

All Articles