1
I am studying in C and I am creating a program that exchanges messages between pc’s in client/server style. Created an array of sockets and threaded them.
 int main ()
  {
    pthread_t *servidor = malloc(sizeof(int*)*2);
    pthread_t gui;
    int porta = 5553;
    void *statusConexao;
    //pthread_create(&gui, NULL, iniciaGui,NULL);
      for (int i = 0; i < 2; i++)
    {
    pthread_create (&servidor[i], NULL, AtivarServidor,(void *)(porta+i));
   }
  for(int i = 0; i <= 2; i++)
 {
  pthread_join (servidor[i], &statusConexao);
  printf("retorno e: %d\n",(int)statusConexao);
 }
 }
The goal is that after the connection has been closed on the client side, the function that creates the server in the thread returns 1 when it is called pthread_exit() (within the Activator function), then with this return reopen the connection on that port again.
It turns out that, with the code I have, the return is only received after all sockets connections have been closed, I believe it is because the function pthread_join inside a for, someone has a hint of how I can solve this problem?