Re: sleep() bug part 2?
Saurabh Desai <[email protected]> Tue, 13 May 2003 20:37:33 -0500
| Newsgroups | gmane.linux.ngpt.user |
|---|---|
| Message-ID | <[email protected]> |
Toshi,
Looks like you are running this on a UP system.
Yes, this happens due to the nature of NGPT. NGPT thread scheduling
is done in a co-operative way and it's a non-preemptive scheduler.
On a UP, it's actually M:1 model. When one thread loops on that only one
native thread, there are no way other threads will get chance to run.
You have to use pthread_yield() to let other threads run or create more
native threads using MAXNATIVETHREADS=2.
Hope this helps.
Saurabh Desai
"Satoshi Kawase" <[email protected]>@www-124.ibm.com on 05/12/2003
04:19:19 PM
Sent by: [email protected]
To: "Ngpt Mailing List" <[email protected]>
cc:
Subject: [pthreads-users] sleep() bug part 2?
hi
still trying to figure out why sleep hangs in the program I am porting. I
wrote a simple test program to try to mimic the problems that the program I
am working on is giving me and that also gives me weird results (I assure
you it's extremely short).
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#define SLEEP 2
#define MILLION 1000000
void *thread_func1 (void *arg){
printf ("are we in thread 1?\n");
while (1){
sleep (SLEEP);
printf ("1: after %d second sleep\n", SLEEP1);
}
}
void *thread_func2(void *arg){
printf ("are we in thread 2?\n");
long c = 0;
while (1){
c++;
if (c % MILLION == 0)
printf ("2: after million
iterations\n");
}
}
int main(){
pthread_t our_thread1;
pthread_t our_thread2;
int result;
result = pthread_create (&our_thread1, NULL, thread_func1,
NULL);
if (result != 0)
printf ("thread not created successfully");
result = pthread_create (&our_thread2, NULL, thread_func2,
NULL);
if (result != 0)
printf ("thread not created successfully");
pthread_join (our_thread1, NULL);
pthread_join (our_thread2, NULL);
return 0;
}
My Output looks like this:
are we in thread 1?
are we in thread 2?
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
2: after million iterations
.
.
.
.
.
.
.
And I never get anything from thread 1. Although the program tells us we
have reached thread 1 I never get a thing from it.
I thought that this might be a thread scheduler priority issue and tried
the
command pthread_setscheduler() command to change the priority of the
threads
but GAH... It immediately seg faulted at that command.
Does anyone out there know if this is in fact a bug, or the correct nature
of NGPT, or I am doing something wrong?
Definitely losing sleep over sleep();
-Toshi
[email protected]
_______________________________________________
pthreads-users mailing list
[email protected]
http://www-124.ibm.com/developerworks/oss/mailman/listinfo/pthreads-users