Pthread Priority on Non PREEMPT Linux Kernels
I've recently been exposed to <pthread.h>, which is is a Unix/Linux (POSIX) API for multi-threading. While playing around with the code and trying to prioritize certain threads so that they execute prior to other threads, I realized that my scheduling parameters, although do not return any errors, are being ignored by the the OS. Threads which I've set to the highest priority do not appear to have executed prior to threads with lower priority. I have been previously told that the Linux kernel I am running on has to have the PREEMPT (and possibly the RT) configurations to properly prioritize threads. Is that why my programs are not behaving according to my expectations? int main() { pthread_t tid1, tid2; pthread_attr_t attr; struct sched_param param; pthread_attr_init(&attr); pthread_attr_getschedparam(&attr, ¶m); param_sched_priority = 99; pthread_attr_setschedpolicy(&attr, ¶m); pthread_attr_setschedparam(&attr, ¶m); pthread_create(&tid1, &attr, myFunc1, NULL); pthread_attr_init(&attr); pthread_attr_getschedparam(&attr, ¶m); param_sched_priority = 1; pthread_attr_setschedpolicy(&attr, ¶m); pthread_attr_setschedparam(&attr, ¶m); pthread_create(&tid1, &attr, myFunc2, NULL); pthread_join(tid1, NULL); pthread_join(tid2, NULL); }