16 if (pipe2(pipefd, O_CLOEXEC) == -1) {
20 stop_fd_read = pipefd[0];
21 stop_fd_write = pipefd[1];
22 pthread_create(&worker_thread, NULL, &Thread::do_work_thunk, this);
31 err = write(stop_fd_write, &ch, 1);
32 } while (err == -1 && errno == EINTR);
40 err = close(stop_fd_write);
41 } while (err == -1 && errno == EINTR);
45 // Can continue (we have close-on-exec).
48 pthread_kill(worker_thread, SIGHUP);
49 if (pthread_join(worker_thread, NULL) == -1) {
50 perror("pthread_join");
55 err = close(stop_fd_read);
56 } while (err == -1 && errno == EINTR);
60 // Can continue (we have close-on-exec).
64 void *Thread::do_work_thunk(void *arg)
66 Thread *thread = reinterpret_cast<Thread *>(arg);