LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-18-2006, 01:27 PM   #1
arunka
Member
 
Registered: Mar 2005
Posts: 60

Rep: Reputation: 15
Thread Creation failing


Hi all
i have a small program written something lke this.

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *dummy(void *arg)
{

}

int main()
{
pthread_t tid;
int i=0
while(i<1024)
{
pthread_create(&tid, NULL,&dummy, NULL)
i++;
printf("i = %d\n", i);
pthread_exit(tid);
}
}

In this i am creating a thread and exiting the thread also.
After 1024 times i am getting error in creating the thread with ernno as 12 --ERRNOMEM.
why is this happenning??
can any one help me?

Thanks in advance
Arun KA
 
Old 07-18-2006, 04:27 PM   #2
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Hi,

Uh, I'm not sure what results you are getting but that code terminates during the first loop iteration. After printing out your "i = %d\n" line you call the pthread_exit(tid) function. This will nuke your main thread without ever executing multiple times.

Given that sample code, I don't see how you could have ever tested out 1024 thread creations. If you simply did a typo and meant for the pthread_exit() function to be called from your dummy() function, then I can see how you can get 1024 iterations of your loop.

I played around a little with your code presuming that you had intended for the pthread_exit() function to be called from within the dummy() function. On my test system here at work it seemed to work correctly. (Redhat 9 distro) however I have experienced your error condition in the past using a Fedora Core 4 distro. I traced it down to what looks like memory leaks in the libraries. The only way I could recover that memory was to re-boot my system.

It may be that.

I hope that this helps!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
eth1 failing on boot, IEEE firewire card driver failing, help jackuss_169 Linux - Laptop and Netbook 5 03-05-2005 08:34 AM
Main thread sending notification to child thread rajesh_b Programming 1 09-22-2004 10:15 AM
configure qt thread issue (just compiled qt w/ -thread option) cleff Linux - Software 8 05-08-2004 12:11 AM
LILO install failing, Boot failing, but Installation fine. sramelyk Slackware 9 08-23-2003 03:37 PM
X failing to load; AddScreen/InitScreen failing for driver 0 weblion Linux - Software 1 08-01-2002 07:14 AM


All times are GMT -5. The time now is 08:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration