From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7EC071F55B for ; Wed, 27 May 2020 08:30:37 +0000 (UTC) Received: from localhost ([::1]:40522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdrSO-0002eF-MG for normalperson@yhbt.net; Wed, 27 May 2020 04:30:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdrSG-0002dp-By for bug-gnulib@gnu.org; Wed, 27 May 2020 04:30:28 -0400 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::3]:20536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdrSE-00018w-Aq for bug-gnulib@gnu.org; Wed, 27 May 2020 04:30:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1590568221; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=/ddsBWl8khhGPksC5sJps51gnksCkAl8Rh5xEEMOmoI=; b=RGrPqXZ7cvjTv0MML9yJv8pZcdfJQVERvYorrzQ7Oe9H9KOLdPPEhaudo6+NjA3nPf yw1Mh5q/d5S6/C8ty1uUftxZE68gcgak9FlLe9/8YNoOgsfvLVQq2AVfFQ4bKSfBUAw9 KUn8AWBiHEi2Qw0A3YjLqUSd0b4AxOZuBg0ztesW9qKmW8z3bz4ociv1vAwzRzNPW3Fn nz+sCKXa81MlimxNtKQotVOxcwEln28xrMqa9oXQa9mJR516eUgnx76zBYvURCSSlpSb qTKvsn8BNJ8HOwfPEUQsXvTPl4GCrfn0KT+nrVgyyxnUCI6zxE1h69so8HQpx2nnWt5p jkew== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6fzxfs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.7.0 DYNA|AUTH) with ESMTPSA id x0bd30w4R8ULg0m (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Wed, 27 May 2020 10:30:21 +0200 (CEST) From: Bruno Haible To: Marc =?ISO-8859-1?Q?Nieper=2DWi=DFkirchen?= Subject: Re: Module suggestion: Atomic operations Date: Wed, 27 May 2020 10:30:20 +0200 Message-ID: <2454360.YjHbtMp5NW@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <2291895.3fLFq5TaVb@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=2a01:238:20a:202:5300::3; envelope-from=bruno@clisp.org; helo=mo6-p00-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hi Marc, > At least one type in is guaranteed to be > lock-free, the atomic flag. Since C18, it can be used in signal > handlers, where Posix locks won't work because they are not > async-safe. Moreover, provides memory fences, which I > don't know how to emulate in general and which also seem to be crucial > in signal handlers of multithreaded applications. > > It seems to me that a substitute of needs to know a bit > about the underlying compiler (so that builtins can be used) or the > underlying architecture (for example, x86 does not need memory fences > with the release or acquire memory order. Unfortunately, my knowledge > about other compilers than gcc or other architectures than x86 is > limited. I could provide the skeleton of a substitute, but it would > need other people to add their architectures. Once things become compiler and architecture dependent, there are a lot of (compiler, architecture) pairs to support. Using gcc/clang unless mentioned otherwise: - i386: Linux, Solaris, macOS, Hurd, FreeBSD, NetBSD, OpenBSD, Haiku, Cygwin, mingw, - i386: Solaris (cc) - i386: Windows (MSVC) - x86_64: Linux, Solaris, macOS, FreeBSD, NetBSD, OpenBSD, Haiku, Cygwin, mingw, - x86_64: Solaris (cc) - x86_64: Windows (MSVC) - x86_64: Linux with x32 ABI (CC="gcc -mx32") - m68k: Linux - mips: Linux 32-bit, little-endian and big-endian - mips: Linux n32, little-endian and big-endian - mips: Linux 64-bit, little-endian and big-endian - mips: IRIX 6.5 (CC="gcc -mabi=n32") - sparc: Linux, Solaris, NetBSD - sparc: Solaris (cc) - sparc64: Linux, Solaris, NetBSD - sparc64: Solaris (cc) - alpha: Linux - hppa: Linux - arm: Linux - arm64: Linux, FreeBSD - powerpc: Linux, macOS, AIX - powerpc: AIX (xlc) - powerpc64: Linux (little-endian and big-endian), AIX - powerpc64: AIX (xlc) - ia64: Linux - s390: Linux - s390x: Linux - riscv32: Linux with ilp32d ABI. - riscv64: Linux with lp64d ABI. It is a *lot* of work, alone to test these. If you have special code for each of these platforms, we won't be done with it in any reasonable time. Therefore it's essential, IMO, to use platform independent code as far as possible. Compiler builtins (of gcc and clang), like you suggest, are a good way to support a large number of the platforms. But you also have to find a solution for - Solaris (cc) - Windows (MSVC) - AIX (xlc) For some of these, you can get an account on a test machine, see [1]. I agree that atomic flags and memory barriers are the essential ones (and maybe hardest) to support. You can leave testing to others, once the code is expected to work and once you have provided good unit tests. Bruno [1] https://gitlab.com/ghwiki/gnow-how/-/wikis/Platforms/Machines