public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran shared coarrays, committed]
@ 2021-01-10 12:28 Thomas Koenig
  0 siblings, 0 replies; only message in thread
From: Thomas Koenig @ 2021-01-10 12:28 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

Hello world,

after the discussions about PTHREAD_PROCESS_SHARED and after
observing that on Cygwin the program simply hangs because
this flag is not implemented there, the best way is to check
for errors and exit with a clear error message instead of
some mysterious hang.

Committed after OK from Nicolas.

Best regards

	Thomas

libgfortran/ChangeLog:

	* caf_shared/util.c (ERRCHECK): New macro.
	(initialize_shared_mutex): Use it to check return codes.
	(initialize_shared_condition): Likewise.

[-- Attachment #2: px.txt --]
[-- Type: text/plain, Size: 1460 bytes --]

diff --git a/libgfortran/caf_shared/util.c b/libgfortran/caf_shared/util.c
index 683e2f36d63..65b347e7a8c 100644
--- a/libgfortran/caf_shared/util.c
+++ b/libgfortran/caf_shared/util.c
@@ -48,24 +48,33 @@ next_power_of_two (size_t size)
   return 1 << (PTR_BITS - __builtin_clzl (size - 1));
 }
 
+#define ERRCHECK(a) do {	\
+    int rc = a;			\
+    if (rc) {   		\
+      errno = rc;		\
+      perror (#a " failed");	\
+      exit (1);			\
+    }				\
+} while(0)
+
 void
 initialize_shared_mutex (pthread_mutex_t *mutex)
 {
   pthread_mutexattr_t mattr;
-  pthread_mutexattr_init (&mattr);
-  pthread_mutexattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED);
-  pthread_mutex_init (mutex, &mattr);
-  pthread_mutexattr_destroy (&mattr);
+  ERRCHECK (pthread_mutexattr_init (&mattr));
+  ERRCHECK (pthread_mutexattr_setpshared (&mattr, PTHREAD_PROCESS_SHARED));
+  ERRCHECK (pthread_mutex_init (mutex, &mattr));
+  ERRCHECK (pthread_mutexattr_destroy (&mattr));
 }
 
 void
 initialize_shared_condition (pthread_cond_t *cond)
 {
   pthread_condattr_t cattr;
-  pthread_condattr_init (&cattr);
-  pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED);
-  pthread_cond_init (cond, &cattr);
-  pthread_condattr_destroy (&cattr);
+  ERRCHECK (pthread_condattr_init (&cattr));
+  ERRCHECK (pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED));
+  ERRCHECK (pthread_cond_init (cond, &cattr));
+  ERRCHECK (pthread_condattr_destroy (&cattr));
 }
 
 int

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-10 12:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-10 12:28 [patch, fortran shared coarrays, committed] Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).