In a client/server socket program, I'm trying to implement multiple clients in the same server. For that I'm trying to use threads. but when I try to connect with the third terminal to the server, it causes segmentation fault. I'd like to figure out why.
Code:
...
pthread_t thread[50];
int count =0;
...
while(1){
connsockfd = accept(...);
int *sock = malloc(sizeof(int));
*sock = connsockfd;
if (pthread_create(thread[count], NULL, &thread_sec, sock) != 0){
exit(EXIT_FAILURE);
}
count++;
}
sock
a couple of times. That shouldn't be the problem. I'm guessing the real problem is insidethread_sec
, but since you're not showing that, we can't really know, can we? – Cheatah