Bug 125645

Summary: pthread_create does not implement the specified defaults
Product: [Fedora] Fedora Reporter: Bob Cook <bobcook47>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 2CC: charles.simmons, drepper, roland
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-06-17 18:04:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Bob Cook 2004-06-09 16:52:28 UTC
Description of problem:
spt.sched_priority=5;
x=pthread_setschedparam(pthread_self(),SCHED_FIFO,&spt); assert(x==0);
x=pthread_create(&pt,NULL,p,(void *)1234);

according to the man page the
default "schedpolicy" is OTHER
default "schedparam" is 0 and most importantly
default "inheritsched" is EXPLICIT

thus policy of pt should be OTHER and priority 0
instead policy is FIFO and priority is 5

The error induces a context switch on every create which is very
undesirable for master:multiple-worker paradigms


Version-Release number of selected component (if applicable):
2.3.3 stable

How reproducible: Easy


Steps to Reproduce:
#include "pthread.h"
#include <stdio.h>
#include <assert.h>

void *p(void *arg) {
	int i,x; 
	struct sched_param spt={0};
	x=pthread_getschedparam(pthread_self(),&i,&spt);
	assert(x==0);
	printf("p policy=%d priority=%d\n",i,spt.sched_priority);
	pthread_exit((void *)8765);
	return NULL;
}

int main(int argc, char* argv[])
{
	int i,x=0;
	pthread_t pt;
	void *out;
	struct sched_param spt={0};
	x=pthread_getschedparam(pthread_self(),&i,&spt);
	assert(x==0);
	spt.sched_priority=5;
x=pthread_setschedparam(pthread_self(),SCHED_FIFO,&spt); assert(x==0);
	x=pthread_create(&pt,NULL,p,(void *)1234);
	assert(x==0);
	x=pthread_join(pt,&out);
	assert(x==0);
	return 0;
}

  
Actual results:
p policy=0 priority=5


Expected results:
p policy=0 priority=0


Additional info:
Must run as superuser to test.

Comment 1 Jakub Jelinek 2004-06-09 21:38:58 UTC
The man page describes linuxthreads, not NPTL (linuxthreads is the
default pthread library you link against and use its headers, while
at runtime you by default use NPTL).
NPTL defaults to PTHREAD_INHERIT_SCHED.
I looked through the standard and I believe the default is implementation-defined,
but am not 100% sure about this.

Comment 2 Ulrich Drepper 2004-06-17 18:04:12 UTC
There is no default value demanded by the standard.  Inheriting the
value is faster in the implementation.  Programs which wish to not use
the parent thread's value can very easily call pthread_setinheritsched.

Comment 3 Chuck Simmons 2005-11-17 20:15:57 UTC
This is still a bug.  The man page states that the default is not to inherit
attributes.  If you don't make the implementation and the man page agree, then
you will continue to get bug reports.

Thanks for wasting my time by not paying attention to perfectly valid bug reports.