sleep() bug part 2?
"Satoshi Kawase" <[email protected]> Mon, 12 May 2003 17:19:19 -0400
| Newsgroups | gmane.linux.ngpt.user |
|---|---|
| Message-ID | <[email protected]> |
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]