Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 336db7e

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 think the reason it failed on that box is a misconfiguration on my behalf, but that's no reason to hang.)
1 parent 3987e9e commit 336db7e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/test/thread/thread_test.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ main(int argc, char *argv[])
150150
pthread_t thread1,
151151
thread2;
152152
int fd;
153+
int rc;
153154

154155
#ifdef WIN32
155156
WSADATA wsaData;
@@ -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)