Bug 125645 - pthread_create does not implement the specified defaults
Summary: pthread_create does not implement the specified defaults
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-06-09 16:52 UTC by Bob Cook
Modified: 2007-11-30 22:10 UTC (History)
3 users (show)

(edit)
Clone Of:
(edit)
Last Closed: 2004-06-17 18:04:12 UTC


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.