Connecting Tech Pros Worldwide Forums | Help | Site Map

error running p_threads

Ivar
Guest
 
Posts: n/a
#1: Nov 19 '06
Hi,
So basically in my application I have a a main function that does
this...

//Global variables
pthread_t thread_id;

void* threadtest(void * arg) {
while(1) {
printf("Reached this segment\n");
}
return NULL;
}


int main(int argc, char** argv) {
....
printf("We've reached here!\n");
//Line 500

pthread_create(&thread_id,NULL,threadtest,NULL); //Line 501
....
}


So basically, when I run this code, I dont have my "Reached this
segment" line print out to console (so basically I feel the thread is
not being entered). But when I run in gdb, put a break point at line
500 in main (as shown below) and continue stepping, I reach the thread
code and get no errors....What could be the reason that I see no thread
output?? Is it even getting there? Sorry for my english...I can explain
anything more in detail if necessary...

-Ravi


Ivar
Guest
 
Posts: n/a
#2: Nov 20 '06

re: error running p_threads


Hi,
And this is on Solaris machine

-Ravi

Ivar wrote:
Quote:
Hi,
So basically in my application I have a a main function that does
this...
>
//Global variables
pthread_t thread_id;
>
void* threadtest(void * arg) {
while(1) {
printf("Reached this segment\n");
}
return NULL;
}
>
>
int main(int argc, char** argv) {
...
printf("We've reached here!\n");
//Line 500
>
pthread_create(&thread_id,NULL,threadtest,NULL); //Line 501
...
}
>
>
So basically, when I run this code, I dont have my "Reached this
segment" line print out to console (so basically I feel the thread is
not being entered). But when I run in gdb, put a break point at line
500 in main (as shown below) and continue stepping, I reach the thread
code and get no errors....What could be the reason that I see no thread
output?? Is it even getting there? Sorry for my english...I can explain
anything more in detail if necessary...
>
-Ravi
coconut1986@gmail.com
Guest
 
Posts: n/a
#3: Nov 20 '06

re: error running p_threads



I guess the problem is that sub-thread end with the main thread ends,
maybe you can add one line in the main function:

int main(int argc, char** argv) {
printf("We've reached here!\n");


pthread_create(&thread_id,NULL,threadtest,NULL);
while(1);
}

On 11月20日, 上午7时29分, "Ivar" <ravi.sath...@gmail.comwrote:
Quote:
Hi,
So basically in my application I have a a main function that does
this...
>
//Global variables
pthread_t thread_id;
>
void* threadtest(void * arg) {
while(1) {
printf("Reached this segment\n");
}
return NULL;
>
}int main(int argc, char** argv) {
...
printf("We've reached here!\n");
//Line 500
>
pthread_create(&thread_id,NULL,threadtest,NULL); //Line 501
...
>
}So basically, when I run this code, I dont have my "Reached this
segment" line print out to console (so basically I feel the thread is
not being entered). But when I run in gdb, put a break point at line
500 in main (as shown below) and continue stepping, I reach the thread
code and get no errors....What could be the reason that I see no thread
output?? Is it even getting there? Sorry for my english...I can explain
anything more in detail if necessary...

-Ravi
Ian Collins
Guest
 
Posts: n/a
#4: Nov 20 '06

re: error running p_threads


coconut1986@gmail.com wrote:

Please don't top post.
Quote:
On 11月20日, 上午7时29分, "Ivar" <ravi.sath...@gmail.comwrote:
Quote:
>>
>>}So basically, when I run this code, I dont have my "Reached this
>>segment" line print out to console (so basically I feel the thread is
>>not being entered). But when I run in gdb, put a break point at line
>>500 in main (as shown below) and continue stepping, I reach the thread
>>code and get no errors....What could be the reason that I see no thread
>>output?? Is it even getting there? Sorry for my english...I can explain
>>anything more in detail if necessary...
>>
I guess the problem is that sub-thread end with the main thread ends,
maybe you can add one line in the main function:
>
int main(int argc, char** argv) {
printf("We've reached here!\n");
>
>
pthread_create(&thread_id,NULL,threadtest,NULL);
while(1);
}
>
While the cause is correctly identified, the off topic advice is unwise.

Look up pthread_join() to replace the while.

This question should have been posted to comp.programming.threads.

--
Ian Collins.
Ivar
Guest
 
Posts: n/a
#5: Nov 20 '06

re: error running p_threads



coconut1986@gmail.com wrote:
Quote:
I guess the problem is that sub-thread end with the main thread ends,
maybe you can add one line in the main function:
>
int main(int argc, char** argv) {
printf("We've reached here!\n");
>
>
pthread_create(&thread_id,NULL,threadtest,NULL);
while(1);
}
>
On 11月20日, 上午7时29分, "Ivar" <ravi.sath...@gmail.comwrote:
Quote:
Hi,
So basically in my application I have a a main function that does
this...

//Global variables
pthread_t thread_id;

void* threadtest(void * arg) {
while(1) {
printf("Reached this segment\n");
}
return NULL;

}int main(int argc, char** argv) {
...
printf("We've reached here!\n");
//Line 500

pthread_create(&thread_id,NULL,threadtest,NULL); //Line 501
...

}So basically, when I run this code, I dont have my "Reached this
segment" line print out to console (so basically I feel the thread is
not being entered). But when I run in gdb, put a break point at line
500 in main (as shown below) and continue stepping, I reach the thread
code and get no errors....What could be the reason that I see no thread
output?? Is it even getting there? Sorry for my english...I can explain
anything more in detail if necessary...

-Ravi
Sorry about this, but I actually have a while(1) loop doing other
things in the main function....so the thread wouldn't end before the
main functiojn
Ravi

Ian Collins
Guest
 
Posts: n/a
#6: Nov 20 '06

re: error running p_threads


Ivar wrote:
Quote:
>
Sorry about this, but I actually have a while(1) loop doing other
things in the main function....so the thread wouldn't end before the
main functiojn
Try posting to comp.programming.threads.

--
Ian Collins.
Closed Thread