#include #include #include #include #include #include #include #include #define NTHREADS 300 void *thread_function(); int open_fail_num; int open_success; int main(int argc, char *argv[]) { int i, j; pthread_t thread_id[NTHREADS]; for(;;) { for(i=0; i < NTHREADS; i++) { pthread_create(&thread_id[i], NULL, &thread_function, NULL); } for(j=0; j < NTHREADS; j++) { pthread_join(thread_id[j], NULL); } printf("open failures: %i\n", open_fail_num); printf("open success: %i\n", open_success); } } void *thread_function() { int fd; time_t t; // fd = open("/dev/cua0", O_NONBLOCK); // fd = open("/dev/cua0", O_RDWR); fd = open("/dev/tty9", O_RDWR); // if (fd == -1) if (fd < 0) { open_fail_num++; // perror("open"); // exit(1); } else { open_success++; } /* just waste some random time */ t = (time((time_t *)0) &31L) << 6; while (t-- > 0) (void)time((time_t *)0); close(fd); // _exit(0); }