Subj : Re: pthread priority in Linux 2.4 Kernel To : comp.programming.threads From : forSale Date : Tue Aug 02 2005 05:58 pm Thank Dave, for your answer. Our system is designed such a way that I need to have multiple prority threads. To prove the priority scheme is working in LINUX pthread environment I needed to test a small program. You are right about STDIO blocking, which might give just enough time to lower prority thread to run. In real-time system, lower prority thread never runs util the higher priority thread is blocked .. I know Linux is not a real-time system however pthread claims SCHED_FIFO as real-time scheduler. I have modifed my code, in my new code the low priorty thread prints data on the screen and high priorty task does some number crunching. Now in real-time system the low priority task should never get the schedule time. It doesnt seem that way in Linux .. Let me know if you have tried thread priority test before and how would you prove pthread priority scheme is working include #include void * lowPriotiyThread(void *arg) { while (1)) printf ("Thread--- %s \n", (unsigned char *) arg); } void * HighPriotiyThread(void *arg) { int i =0 while (1) i++; } int main () { pthread_attr_t attr; pthread_t thread1, thread2; struct ched_param param; pthread_attr_init(&attr); param.sched_priority =20; pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_attr_setchedparam(&attr, ¶m) pthread_create(&thread1, &attr,lowPriotiyThread, "Thread1"); param.sched_priority =22; pthread_create(&thread2,&attr,HighPriotiyThread, "Thread2"); pthread_join ( thread1, NULL) } Output Thread--- Thread1 Thread--- Thread1 Thread--- Thread1 Thread--- Thread1 Thread--- Thread1 Thread--- Thread1 .......... This output continues never stops. That tells me Linux is still assigning time slice to low priority task. By the way how do I know the system is running on two VIRTUAL CPUs. Thanks Ottawa "David Schwartz" wrote in message news:dcoed9$t2i$1@nntp.webmaster.com... > > "forSale" <@hotmail.com> wrote in message > news:G7qdnURgOZzhEXLfRVn-ug@magma.ca... > > > Now Since thread 2 has higher priority than thread1. Thread1 should never > > get executed once thread2 start to run. Why is the thread1 getting > > executing again. > > Your assumption is definitely wrong. Just because one thread has higher > priority than another, it doesn't mean the other thread won't run! It just > means that if the system ever has to choose which of the two threads to run, > it will choose the higher priority one. But maybe it doesn't have to choose > because it has two virtual CPUs. Or maybe the higher priority thread is > blocked trying to output data to a full buffer. > > DS > > .