Skip to content

Commit fd4bc2f

Browse files
committed
fix thread conflict when passing arg as pointer
1 parent 75b9a06 commit fd4bc2f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

httpd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <pthread.h>
2626
#include <sys/wait.h>
2727
#include <stdlib.h>
28+
#include <stdint.h>
2829

2930
#define ISspace(x) isspace((int)(x))
3031

@@ -53,7 +54,7 @@ void unimplemented(int);
5354
/**********************************************************************/
5455
void accept_request(void *arg)
5556
{
56-
int client = *(int*)arg;
57+
int client = (intptr_t)arg;
5758
char buf[1024];
5859
size_t numchars;
5960
char method[255];
@@ -500,7 +501,7 @@ int main(void)
500501
if (client_sock == -1)
501502
error_die("accept");
502503
/* accept_request(client_sock); */
503-
if (pthread_create(&newthread , NULL, (void *)accept_request, (void *)&client_sock) != 0)
504+
if (pthread_create(&newthread , NULL, (void *)accept_request, (void *)(intptr_t)client_sock) != 0)
504505
perror("pthread_create");
505506
}
506507

0 commit comments

Comments
 (0)