Skip to content

Commit

Permalink
Update httpd.c
Browse files Browse the repository at this point in the history
fie problem caused by intptr_t
  • Loading branch information
EZLippi committed Apr 18, 2017
1 parent 7abf28e commit 7c55024
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void unimplemented(int);
/**********************************************************************/
void accept_request(void *arg)
{
int client = (intptr_t)arg;
int client = *(int*)arg;
char buf[1024];
size_t numchars;
char method[255];
Expand Down

1 comment on commit 7c55024

@huntinux
Copy link
Contributor

@huntinux huntinux commented on 7c55024 May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议你再看看这个issue:#5
我之前提交的pr:fd4bc2f
同时修改了两个地方,本意是将局部变量的值传递给线程,而不是将局部变量地址传递给线程,因为那样会有问题:

void accept_request(void *arg)
 {
-    int client = *(int*)arg;
+    int client = (intptr_t)arg;
     char buf[1024];
     size_t numchars;
     char method[255];
@@ -500,7 +501,7 @@ int main(void)
         if (client_sock == -1)
             error_die("accept");
         /* accept_request(client_sock); */
-        if (pthread_create(&newthread , NULL, (void *)accept_request, (void *)&client_sock) != 0)
+        if (pthread_create(&newthread , NULL, (void *)accept_request, (void *)(intptr_t)client_sock) != 0)
             perror("pthread_create");
     }

之后其他人又提交了一个pr:5ffc0df

-        /* accept_request(client_sock); */
+        /* accept_request(&client_sock); */
         if (pthread_create(&newthread , NULL, (void *)accept_request, (void *)&client_sock) != 0)

这个pr把pthread_create的地方改回了原来的代码(传递局部变量地址)。但是居然没有把 accept_request 中的地方改回去。而且你还merge了这个pr了。

你今天才发现,还fie problem,你都不知道哪里出错了吧。

这么误人子弟好吗?

Please sign in to comment.