From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: release/acquire memory barriers and ring Date: Fri, 16 Feb 2018 09:58:12 -0800 Message-ID: <20180216095812.7e634a53@xeon-e3> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org To: Alex Kiselev Return-path: Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by dpdk.org (Postfix) with ESMTP id 0BB7D1B2BA for ; Fri, 16 Feb 2018 18:58:16 +0100 (CET) Received: by mail-pl0-f65.google.com with SMTP id g18so2065948plo.7 for ; Fri, 16 Feb 2018 09:58:15 -0800 (PST) In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Tue, 13 Feb 2018 22:37:37 +0300 Alex Kiselev wrote: > Hi. > > I've been wondering should I use a release/acquire memory barrier pair > in order to be sure that the other thread will see the fully/corrected > initialized object > passed to it via a dpdk ring or ring itself is a kind of barrier? > > Let's say I have a pseudo code: > > Thread1: > obj = alloc(); > ... > obj initialization > ... > > ??? fence(memory_order_release); ??? > rte_ring_sp_enqueue(ring, obj) > > > Thread2: > ??? fence(memory_order_acquire); ??? > rte_ring_sc_dequeue(ring, obj) > > Should I use fences in that code? > > Thanks. > > -- > Alex Not necessary. Enqueue/dequeue has necessary ordering; it is built on compare-exchange which has implied barrier.