Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit336db7e

Browse files
committed
Check the return code of pthread_create(). Otherwise we go into an infinite
loop if it fails, which is what what happened on my HP-UX box. (I thinkthe reason it failed on that box is a misconfiguration on my behalf, butthat's no reason to hang.)
1 parent3987e9e commit336db7e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

‎src/test/thread/thread_test.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ main(int argc, char *argv[])
150150
pthread_tthread1,
151151
thread2;
152152
intfd;
153+
intrc;
153154

154155
#ifdefWIN32
155156
WSADATAwsaData;
@@ -199,8 +200,23 @@ main(int argc, char *argv[])
199200
/* Hold lock until we are ready for the child threads to exit. */
200201
pthread_mutex_lock(&init_mutex);
201202

202-
pthread_create(&thread1,NULL, (void*(*) (void*))func_call_1,NULL);
203-
pthread_create(&thread2,NULL, (void*(*) (void*))func_call_2,NULL);
203+
rc=pthread_create(&thread1,NULL, (void*(*) (void*))func_call_1,NULL);
204+
if (rc!=0)
205+
{
206+
fprintf(stderr,"Failed to create thread 1: %s **\nexiting\n",
207+
strerror(rc));
208+
exit(1);
209+
}
210+
rc=pthread_create(&thread2,NULL, (void*(*) (void*))func_call_2,NULL);
211+
if (rc!=0)
212+
{
213+
/*
214+
* strerror() might not be thread-safe, and we already spawned thread
215+
* 1 that uses it
216+
*/
217+
fprintf(stderr,"Failed to create thread 2 **\nexiting\n");
218+
exit(1);
219+
}
204220

205221
while (thread1_done==0||thread2_done==0)
206222
sched_yield();/* if this is a portability problem, remove it */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp