Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-23-2005, 04:59 PM   #1
LQ Newbie
Registered: May 2005
Location: Canada
Distribution: Windows XP SP2
Posts: 2

Rep: Reputation: 0
error on pthread_create?


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...

		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);
				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.


Old 05-23-2005, 06:46 PM   #2
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, 07:21 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,541

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

Then execute your program


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 02:44 AM
pthread_create... os2 Programming 4 05-26-2005 04:09 PM
Pthread_create rahul_kulkarni Programming 4 02-10-2005 12:48 PM
pthread_create tushar123 Programming 2 06-07-2004 09:15 AM
pthread_create parameters AquamaN Programming 3 03-16-2004 11:05 AM > Forums > Non-*NIX Forums > Programming

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

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