#include #include #include #include #include static void *thr(void *arg) { int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); const int y = 1; struct sockaddr_in new_conn; socklen_t new_conn_len = sizeof(new_conn); setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &y, sizeof(y)); listen(fd, SOMAXCONN); accept(fd, (void *)&new_conn, &new_conn_len); printf("finished\n"); return NULL; } int main(void) { pthread_t id; pthread_create(&id, NULL, thr, NULL); sleep(1); pthread_cancel(id); pthread_join(id, NULL); return 0; }