summaryrefslogtreecommitdiff
path: root/src/test/thread
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2011-05-27 11:51:23 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2011-05-27 12:55:02 +0300
commit336db7e3474508b46a0e6bdb013a8bee5aac9adf (patch)
treec8cebe505142e0448e791d249566cd39a2a4e4af /src/test/thread
parent3987e9e62046bd800d8d08566ed49fee1ae6cb86 (diff)
downloadpostgresql-336db7e3474508b46a0e6bdb013a8bee5aac9adf.tar.gz
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.)
Diffstat (limited to 'src/test/thread')
-rw-r--r--src/test/thread/thread_test.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/test/thread/thread_test.c b/src/test/thread/thread_test.c
index 0782e8c66b..6a81829912 100644
--- a/src/test/thread/thread_test.c
+++ b/src/test/thread/thread_test.c
@@ -150,6 +150,7 @@ main(int argc, char *argv[])
pthread_t thread1,
thread2;
int fd;
+ int rc;
#ifdef WIN32
WSADATA wsaData;
@@ -199,8 +200,23 @@ main(int argc, char *argv[])
/* Hold lock until we are ready for the child threads to exit. */
pthread_mutex_lock(&init_mutex);
- pthread_create(&thread1, NULL, (void *(*) (void *)) func_call_1, NULL);
- pthread_create(&thread2, NULL, (void *(*) (void *)) func_call_2, NULL);
+ rc = pthread_create(&thread1, NULL, (void *(*) (void *)) func_call_1, NULL);
+ if (rc != 0)
+ {
+ fprintf(stderr, "Failed to create thread 1: %s **\nexiting\n",
+ strerror(rc));
+ exit(1);
+ }
+ rc = pthread_create(&thread2, NULL, (void *(*) (void *)) func_call_2, NULL);
+ if (rc != 0)
+ {
+ /*
+ * strerror() might not be thread-safe, and we already spawned thread
+ * 1 that uses it
+ */
+ fprintf(stderr, "Failed to create thread 2 **\nexiting\n");
+ exit(1);
+ }
while (thread1_done == 0 || thread2_done == 0)
sched_yield(); /* if this is a portability problem, remove it */