Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, the SerenityOS developers.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <pthread.h>
8#include <stdio.h>
9#include <sys/select.h>
10#include <unistd.h>
11
12int pipefds[2];
13
14int main(int, char**)
15{
16 pipe(pipefds);
17
18 pthread_t tid;
19 pthread_create(
20 &tid, nullptr, [](void*) -> void* {
21 sleep(1);
22 printf("ST: close()\n");
23 close(pipefds[1]);
24 pthread_exit(nullptr);
25 },
26 nullptr);
27
28 fd_set rfds;
29 FD_ZERO(&rfds);
30 FD_SET(pipefds[1], &rfds);
31
32 printf("MT: select()\n");
33 int rc = select(pipefds[1] + 1, &rfds, nullptr, nullptr, nullptr);
34 if (rc < 0) {
35 perror("select");
36 return 1;
37 }
38
39 printf("ok\n");
40 return 0;
41}