Subj : how to use select in each thread To : comp.programming.threads From : Zongjun Qi Date : Sun Apr 17 2005 09:40 am I am doing a router simulation. The router gets data from several TCP/UDP inputs, and do some processing. My architecture is: A main thread is router, then for simulation of each TCP/UDP flow, I create a thread. Because each TCP may have different round-trip time, I would like to use a timer for each TCP thread. But as I spent 4 days googling the Linux world, the answer seems to be only build a timer queue! I am wondering if I can do by repeating select(0,NULL,NULL,NULL,&tv)function in each thread. But as the my output displays, when a thread gets its time slice, it will do select many times(time slice>tv), and only when its time slice is over, the next thread gets its own, and do a multiple times of select. While what I really want to realize is their total independence. below is the code. --------------- /**************************************************/ #include #include #include #define MAX_THREADS 5 int sum; /* this data is shared by the thread(s) */ pthread_t tid[MAX_THREADS]; /* the thread identifiers */ void *runner(void * param); main(int argc, char *argv[]) { int num_threads, i; pthread_attr_t attr; /* set of thread attributes */ struct sched_param sp; sp.sched_priority = sched_get_priority_min( SCHED_RR ); if (argc != 2) { fprintf(stderr, "usage: a.out \n"); exit(); } if (atoi(argv[1]) <= 0) { fprintf(stderr,"%d must be > 0\n", atoi(argv[1])); exit(); } if (atoi(argv[1]) > MAX_THREADS) { fprintf(stderr,"%d must be <= %d\n", atoi(argv[1]), MAX_THREADS); exit(); } num_threads = atoi(argv[1]); printf("The number of threads is %d\n", num_threads); /* get the default attributes */ pthread_attr_init(&attr); /* create the threads */ for (i=0; i