Serenity Operating System
at portability 36 lines 687 B view raw
1#include <pthread.h> 2#include <stdio.h> 3#include <sys/select.h> 4#include <unistd.h> 5 6int pipefds[2]; 7 8int main(int, char**) 9{ 10 pipe(pipefds); 11 12 pthread_t tid; 13 pthread_create( 14 &tid, nullptr, [](void*) -> void* { 15 sleep(1); 16 printf("ST: close()\n"); 17 close(pipefds[1]); 18 pthread_exit(nullptr); 19 return nullptr; 20 }, 21 nullptr); 22 23 fd_set rfds; 24 FD_ZERO(&rfds); 25 FD_SET(pipefds[1], &rfds); 26 27 printf("MT: select()\n"); 28 int rc = select(pipefds[1] + 1, &rfds, nullptr, nullptr, nullptr); 29 if (rc < 0) { 30 perror("select"); 31 return 1; 32 } 33 34 printf("ok\n"); 35 return 0; 36}