LinuxQuestions.org
Register a domain and help support LQ
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 05-23-2005, 03:59 PM   #1
adamjmac
LQ Newbie
 
Registered: May 2005
Location: Canada
Distribution: Windows XP SP2
Posts: 2

Rep: Reputation: 0
error on pthread_create?


Hello,

I am writing parallel code for a physics simulation that creates and joins threads very fast. I never have more than 5 or 6 threads active at once, however. After the simulation runs for about half a million iterations, pthread_create starts returning EAGAIN and not creating the thread. This causes long pauses because I have to while(pthread_create);.

As another note, Windows has a maximum thread limit of 2019 or so, and the program works perfectly on Windows. The maximum thread limit of the UNIX system that the problem exists on has a thread limit of over 8000. Also, by watching the number of active threads in top and task manager, I can see that it is not increasing over time.

I also know that there is plenty of memory for the program, a lack of memory would likely cause one of many other malloc()'s to fail, not a tiny little pthread_create call.

What are possible causes for this issue? I tried memset()-ing my pthread variables to zero before calling pthread_create and this actually made the problem occur less often.

Here is the block that creates the threads...

Code:
		printf("|%d|", me); fflush(stdout);

		// Create work threads for each interaction
		for (i=0, j=me; i<=p[me].t_num; j=p[me].t_box[i++]) {
			memset(p[j].a_, 0, p[j].num*12);
			if (i) {
				printf("[a"); fflush(stdout);
				k = pthread_create(&attach_t[i-1], NULL, attach, &i);
				printf("%d", k); fflush(stdout);
				if (k) exit(0);
				pthread_mutex_lock(&arg3_mutex);
				printf("]"); fflush(stdout);
			} else {
				printf("[c"); fflush(stdout);
				k = pthread_create(&calc_t, NULL, calc, NULL);
				printf("%d]", k); fflush(stdout);
				if (k) exit(0);
			}
		}
		printf("(r)"); fflush(stdout);

...

		// Join work threads
		pthread_join(calc_t, NULL);
		memset(&calc_t, 0, sizeof(pthread_t));
		for (i=0; i<p[me].t_num; i++) pthread_join(attach_t[i], NULL);
		memset(attach_t, 0, p[me].t_num*sizeof(pthread_t));
Any suggestions would be appreciated. The code must run stably for a long time on both windows and unix.

Thanks,

Adam
 
Old 05-23-2005, 05:46 PM   #2
adamjmac
LQ Newbie
 
Registered: May 2005
Location: Canada
Distribution: Windows XP SP2
Posts: 2

Original Poster
Rep: Reputation: 0
Seems the while() fixed the problem. The most it will error out in a row is 2 or 3 times.

Thanks anyway.
 
Old 05-23-2005, 06:21 PM   #3
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,546

Rep: Reputation: 119Reputation: 119
if you want to limit the number of threads to 2019, try from a bash shell :
ulimit -u 2019

Then execute your program
 
  


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
pthread_create returned an error. 12 12 davebwithane Linux - Software 6 09-29-2009 01:44 AM
pthread_create... os2 Programming 4 05-26-2005 03:09 PM
Pthread_create rahul_kulkarni Programming 4 02-10-2005 11:48 AM
pthread_create tushar123 Programming 2 06-07-2004 08:15 AM
pthread_create parameters AquamaN Programming 3 03-16-2004 10:05 AM


All times are GMT -5. The time now is 03:33 AM.

Main Menu
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