linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* futex priority based wakeup
@ 2007-09-07 15:02 Benedict, Michael
  2007-09-07 16:41 ` Ilya Lipovsky
  0 siblings, 1 reply; 12+ messages in thread
From: Benedict, Michael @ 2007-09-07 15:02 UTC (permalink / raw)
  To: linuxppc-embedded

I recently upgraded to 2.6.22 to get the priority based futex wakeup
behavior.  However, when I run a simple program (see below), based on
either a pthread_mutex_t or a sem_t, it seems that threads are woken up
in FIFO order.  I am using glibc 2.3.6 with NPTL and TLS, based off
crossdev-0.43.  Could someone help me get priority-based wakeup or point
me to a better place to get this question answered?
	Thank you,
		Michael

Code:

pthread_mutex_t mymutex =3D PTHREAD_MUTEX_INITIALIZER;

void *important(void *ign)
{
        sleep(1);
        printf("important waiting for mutex\n");
        if(pthread_mutex_lock(&mymutex)) {
                perror("sem_wait");
                exit(1);
        } else {
                printf("important got mutex!\n");
                pthread_mutex_unlock(&mymutex);
        }

        return NULL;
}


void *unimportant(void *ign)
{
        printf("unimportant waiting for mutex\n");
        if(pthread_mutex_lock(&mymutex)) {
                perror("sem_wait");
                exit(1);
        } else {
                printf("unimportant got mutex!\n");
                pthread_mutex_unlock(&mymutex);
        }

        return NULL;
}

int main()
{
        struct sched_param p;
        pthread_attr_t attr;
        pthread_t i, u;

        pthread_mutex_lock(&mymutex);

        p.__sched_priority =3D sched_get_priority_min(SCHED_FIFO);
        if(-1 =3D=3D p.__sched_priority) {
                perror("sched_get_priority_min");
                return 1;
        }
        pthread_attr_init(&attr);
        pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
        pthread_attr_setschedparam(&attr, &p);
        pthread_create(&u, &attr, unimportant, NULL);

        p.__sched_priority =3D sched_get_priority_max(SCHED_FIFO);
        pthread_attr_setschedparam(&attr, &p);
        pthread_create(&i, &attr, important, NULL);

        sleep(5);
        printf("main unlocking mutex\n");
        pthread_mutex_unlock(&mymutex);

        pthread_join(u, NULL);
        pthread_join(i, NULL);

        return 0;
}

Which produces:
unimportant waiting for mutex
important waiting for mutex
main unlocking mutex
unimportant got mutex!
important got mutex!

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-09-12 14:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-07 15:02 futex priority based wakeup Benedict, Michael
2007-09-07 16:41 ` Ilya Lipovsky
2007-09-07 17:16   ` Ilya Lipovsky
2007-09-07 17:24     ` Benedict, Michael
2007-09-07 17:45       ` Ilya Lipovsky
2007-09-07 17:54         ` Benedict, Michael
2007-09-10 18:51         ` Benedict, Michael
2007-09-10 21:41         ` Benedict, Michael
2007-09-11 22:59           ` Ilya Lipovsky
2007-09-12  0:14             ` Nguyen Nguyen
2007-09-12  1:09               ` Ilya Lipovsky
2007-09-12 14:56               ` Benedict, Michael

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).