#include #include #include #include #include void *thread(void *num) { int i=*((int *) num); setpriority(PRIO_PROCESS,getpid(),i); sleep(rand()%(i+1)); printf ("Thread #%d working hard with priority %d!\n",i,getpriority(PRIO_PROCESS,getpid())); return(NULL); } int main (void) { pthread_t tid[10]; int i; for(i=0;i<10; i++) { printf("Starting %dth thread\n",i); pthread_create(&tid[i], NULL, thread, &i); } printf("All threads started!\n"); if (pthread_join(tid[0], NULL)) { for(i=1;i<10; i++) { pthread_cancel(tid[i]); } } printf ("All threads stopped!\n"); return (0); }