From patchwork Sun Jan 10 12:28:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1424241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=NSmP1hdt; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DDGNj2spjz9sRK for ; Sun, 10 Jan 2021 23:29:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 806C9385781C; Sun, 10 Jan 2021 12:28:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 806C9385781C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610281734; bh=7vWdtULac/1kiqjrTJUQjXcv8+PJeBscEh7JZCmkIBw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NSmP1hdti2E5LP9rX5ja/hzbC7gMRApX4YMXClz0wwZxqXGL1zXCkWiRreIWYXlTT oLKkTP4ZGlKzNEwByJ+ENNAY1HjrLaluzuxjxug5UzeNRmMSuN20nMCwCiHZnbREsf UWCJHv5dai26PqwiFFYpkW9dYRa/f+1J+DTIE5vM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout2.netcologne.de (cc-smtpout2.netcologne.de [IPv6:2001:4dd0:100:1062:25:2:0:2]) by sourceware.org (Postfix) with ESMTPS id 0C6443857C52; Sun, 10 Jan 2021 12:28:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0C6443857C52 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 216A2128DF; Sun, 10 Jan 2021 13:28:45 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 1110111EED; Sun, 10 Jan 2021 13:28:45 +0100 (CET) Received: from [2001:4dd7:2366:0:404f:fe14:e36c:a144] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5ffaf2fd-024d-7f0000012729-7f000001ac9e-1 for ; Sun, 10 Jan 2021 13:28:45 +0100 Received: from linux-p51k.fritz.box (2001-4dd7-2366-0-404f-fe14-e36c-a144.ipv6dyn.netcologne.de [IPv6:2001:4dd7:2366:0:404f:fe14:e36c:a144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Sun, 10 Jan 2021 13:28:43 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran shared coarrays, committed] Message-ID: Date: Sun, 10 Jan 2021 13:28:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 Content-Language: de-DE X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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. 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