From c0e81195b7e1fc1db66b4c324ba0d356ef7a0032 Mon Sep 17 00:00:00 2001 From: "hp.com!davidm" Date: Tue, 3 May 2005 09:13:17 +0000 Subject: [PATCH] (doit): Fail gracefully if we fail to create all NTHREADS threads. (Logical change 1.290) --- tests/Gtest-concurrent.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/Gtest-concurrent.c b/tests/Gtest-concurrent.c index 638ad342..8fe2ef30 100644 --- a/tests/Gtest-concurrent.c +++ b/tests/Gtest-concurrent.c @@ -1,5 +1,5 @@ /* libunwind - a platform-independent unwind library - Copyright (C) 2003-2004 Hewlett-Packard Co + Copyright (C) 2003-2005 Hewlett-Packard Co Contributed by David Mosberger-Tang Permission is hereby granted, free of charge, to any person obtaining @@ -84,7 +84,13 @@ doit (void) int i; for (i = 0; i < NTHREADS; ++i) - pthread_create (th + i, NULL, worker, NULL); + if (pthread_create (th + i, NULL, worker, NULL)) + { + fprintf (stderr, "FAILURE: Failed to create %u threads " + "(after %u threads)\n", + NTHREADS, i); + exit (-1); + } for (i = 0; i < NTHREADS; ++i) pthread_join (th[i], NULL); @@ -110,7 +116,10 @@ main (int argc, char **argv) unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_PER_THREAD); if (nerrors) - fprintf (stderr, "FAILURE: detected %d errors\n", nerrors); + { + fprintf (stderr, "FAILURE: detected %d errors\n", nerrors); + exit (-1); + } if (verbose) printf ("SUCCESS\n");