* possible problems with kernel threading code?
@ 2004-02-20 18:08 Chris Friesen
2004-02-20 19:43 ` Ulrich Drepper
0 siblings, 1 reply; 3+ messages in thread
From: Chris Friesen @ 2004-02-20 18:08 UTC (permalink / raw)
To: linux-kernel
I'm running the following code under 2.4.18-2.4.20, with the standard
thread library, and sometimes I get an error of "No such process". How
can this possibly happen? The pthread_setschedparam() call is running
in the thread that it is trying to operate on, but somehow it can't find
itself?
I also have managed to trigger reboots with this code, and I'm not sure how.
Anyone have any ideas? Is this a kernel problem? I can trigger it on
ppc hardware under kernel versions 2.4.18-2.4.20 and a modified 2.4.22.
(I haven't tried 2.4.21) My x86 with a 2.4.18-19.8.0 redhat kernel
doesn't show the problem.
Thanks,
Chris
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
pthread_t t1;
void *func(void *p)
{
pid_t pid;
int status;
struct sched_param schedParam;
int policy = SCHED_RR;
int priority = 40;
schedParam.sched_priority = priority;
int schedRc = pthread_setschedparam(t1, policy, &schedParam);
if (schedRc){
fprintf(stderr, "pthread_setschedparam error:%s, priority:%d,
policy:%d\n",strerror(schedRc), priority, policy);
}
pthread_exit(EXIT_SUCCESS);
return 0;
}
int main(int argc, char **argv)
{
pthread_create(&t1, 0, func,(void*)1);
pthread_join(t1,0);
return 0;
}
--
Chris Friesen | MailStop: 043/33/F10
Nortel Networks | work: (613) 765-0557
3500 Carling Avenue | fax: (613) 765-2986
Nepean, ON K2H 8E9 Canada | email: cfriesen@nortelnetworks.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: possible problems with kernel threading code?
2004-02-20 18:08 possible problems with kernel threading code? Chris Friesen
@ 2004-02-20 19:43 ` Ulrich Drepper
2004-02-20 20:58 ` Chris Friesen
0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Drepper @ 2004-02-20 19:43 UTC (permalink / raw)
To: Chris Friesen; +Cc: linux-kernel
Not that this is of any interest for this list but what the heck.
The problem is your code.
> int schedRc = pthread_setschedparam(t1, policy, &schedParam);
There is no guarantee that t1 is filled before you it here in the newly
created thread. Only when pthread_create() returns is the thread handle
guaranteed to be written.
--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: possible problems with kernel threading code?
2004-02-20 19:43 ` Ulrich Drepper
@ 2004-02-20 20:58 ` Chris Friesen
0 siblings, 0 replies; 3+ messages in thread
From: Chris Friesen @ 2004-02-20 20:58 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: linux-kernel
Ulrich Drepper wrote:
> Not that this is of any interest for this list but what the heck.
I thought that the kernel hangs might be of interest.
> The problem is your code.
>> int schedRc = pthread_setschedparam(t1, policy, &schedParam);
>
> There is no guarantee that t1 is filled before you it here in the newly
> created thread. Only when pthread_create() returns is the thread handle
> guaranteed to be written.
Ah, that explains the error. I'm still trying to track down the kernel
hangs though.
Chris
--
Chris Friesen | MailStop: 043/33/F10
Nortel Networks | work: (613) 765-0557
3500 Carling Avenue | fax: (613) 765-2986
Nepean, ON K2H 8E9 Canada | email: cfriesen@nortelnetworks.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-02-20 20:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-20 18:08 possible problems with kernel threading code? Chris Friesen
2004-02-20 19:43 ` Ulrich Drepper
2004-02-20 20:58 ` Chris Friesen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox