| 1 | #include <sys/time.h> // work around module map issue with iOS sdk, <rdar://problem/35159346> |
|---|---|
| 2 | #include <sys/select.h> |
| 3 | #include <stdio.h> |
| 4 | #include <pthread.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | void * |
| 8 | select_thread (void *in) |
| 9 | { |
| 10 | pthread_setname_np ("select thread"); |
| 11 | fd_set fdset; |
| 12 | FD_SET (STDIN_FILENO, &fdset); |
| 13 | while (1) |
| 14 | select (nfds: 2, readfds: &fdset, NULL, NULL, NULL); |
| 15 | return NULL; |
| 16 | } |
| 17 | |
| 18 | void stopper () |
| 19 | { |
| 20 | while (1) |
| 21 | sleep(seconds: 1); // break here |
| 22 | } |
| 23 | |
| 24 | int main () |
| 25 | { |
| 26 | pthread_setname_np ("main thread"); |
| 27 | pthread_t other_thread; |
| 28 | pthread_create (newthread: &other_thread, NULL, start_routine: select_thread, NULL); |
| 29 | sleep (seconds: 1); |
| 30 | stopper(); |
| 31 | } |
| 32 |
