Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

race condition #8

Open
jingsong-liu opened this issue Sep 14, 2017 · 0 comments
Open

race condition #8

jingsong-liu opened this issue Sep 14, 2017 · 0 comments

Comments

@jingsong-liu
Copy link
Owner

 int new_fd = accept(server_sock, (struct sockaddr*)&client_addr, &client_addr_len);
...
 cargs.fd = new_fd;
 if(0 != pthread_create(&pid, NULL, cli_conn, (void *)&cargs)) {
...
void *
cli_conn(void* arg)
{
    int sock = ((struct cli_args*)arg)->fd;
...

There is a race condition between accept a connection and thread routine's assigning new connection fd to sock, if next accept comes before current connection thread's sock assignment, int sock = ((struct cli_args*)arg)->fd, then two connection thread will refer to same socket file description, its dangerous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant