Skip to contentSkip to conversation

fix pthread_create regression

PATCH New Jan Kiszka 1 participant 1 message Jul 8, 2007

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 fix pthread_create regression

My rt-caps patch included an ugly regression for the posix skin:

pthread_create fails if the caller passes SCHED_FIFO + a priority > 0 in the thread attribute. It's observable via switchtest for instance. This patch should fix it.

Note that 2.3.x urgently needs this patch as well!

Jan

skins/posix/thread.c +4 -2
Index: src/skins/posix/thread.c
===================================================================
@@ -139,7 +139,7 @@ int __wrap_pthread_create(pthread_t *tid
 
 	if (!attr) {
 		policy = SCHED_OTHER;
-		param.sched_priority = 0;
+		iargs.prio = 0;
 	} else {
 		pthread_attr_getinheritsched(attr, &inherit);
 		if (inherit == PTHREAD_EXPLICIT_SCHED) {
@@ -149,12 +149,15 @@ int __wrap_pthread_create(pthread_t *tid
 			/* inherit == PTHREAD_INHERIT_SCHED */
 			__wrap_pthread_getschedparam(pthread_self(),
 						     &policy, &param);
+		iargs.prio = param.sched_priority;
 
 		/* Work around linuxthreads shortcoming: it doesn't believe
 		   that it could have RT power as non-root and fails the
 		   thread creation overeagerly. */
 		memcpy(&iattr, attr, sizeof(pthread_attr_t));
+		param.sched_priority = 0;
 		pthread_attr_setschedpolicy(&iattr, SCHED_OTHER);
+		pthread_attr_setschedparam(&iattr, &param);
 		attr = &iattr;
 	}
 
@@ -164,7 +167,6 @@ int __wrap_pthread_create(pthread_t *tid
 	iargs.start = start;
 	iargs.arg = arg;
 	iargs.policy = policy;
-	iargs.prio = param.sched_priority;
 	iargs.ret = EAGAIN;
 	__real_sem_init(&iargs.sync, 0, 0);