Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jXaLM-0004ct-Rw for pgsql-docs@arkaria.postgresql.org; Sun, 10 May 2020 01:01:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jXaLK-0007iM-8d for pgsql-docs@arkaria.postgresql.org; Sun, 10 May 2020 01:01:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jXaLK-0007iF-2x for pgsql-docs@lists.postgresql.org; Sun, 10 May 2020 01:01:22 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jXaL8-0000gL-HF for pgsql-docs@postgresql.org; Sun, 10 May 2020 01:01:19 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 29DCC1D568052 for ; Sat, 9 May 2020 18:01:05 -0700 (MST) Date: Sat, 9 May 2020 18:01:05 -0700 (MST) From: "postgresql_2016@163.com" To: pgsql-docs@postgresql.org Message-ID: <1589072465169-0.post@n3.nabble.com> Subject: =?UTF-8?Q?=E3=80=90memory_barrier=E3=80=91Should_we_update?= =?UTF-8?Q?_the_README.barrier_description.?= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi When I read the introduction of Weaknesses of Memory Barriers in README.barrier, the following maybe out-of-date now. Even very simple write operations often require additional synchronization. For example, it's not safe for multiple writers to simultaneously execute this code (supposing x is a pointer into shared memory): x->foo++; Although this may compile down to a single machine-language instruction, the CPU will execute that instruction by reading the current value of foo, adding one to it, and then storing the result back to the original address. If two CPUs try to do this simultaneously, both may do their reads before either one does their writes. *Eventually we might be able to use an atomic fetch-and-add instruction for this specific case on architectures that support it, but we can't rely on that being available everywhere, and we currently have no support for it at all. Use a lock.* Now, the postgres has support atomic operation and use it, in some cases we have not use the lock. -- Sent from: https://www.postgresql-archive.org/PostgreSQL-docs-f2165602.html