クライアント接続を受け入れるとフォークするCプログラムを書いています。これが発生したら、2つのスレッドを生成したいのですが、これを機能させることができないようです。
pthread_t t1, t2;
void *r_loop();
void *w_loop();
.
.
.
sockfd = accept(r_sockfd, (struct sockaddr *) &address, &len);
if (sockfd < 0)
printf("Error accepting\n");
if (!fork())
{
int r_thread = pthread_create(&t1, NULL, r_loop, NULL);
int w_thread = pthread_create(&t2, NULL, w_loop, NULL);
pthread_join(r_thread, NULL);
pthread_join(w_thread, NULL);
exit(0);
}
これを実行すると、関数r_loopとw_loopが実行されません。