qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-prote


From: Emilio G. Cota
Subject: Re: [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables
Date: Thu, 13 Oct 2016 15:20:15 -0400
User-agent: Mutt/1.5.24 (2015-08-30)

On Mon, Oct 10, 2016 at 15:59:04 +0200, Paolo Bonzini wrote:
> There is a data race if the variable is written concurrently to the
> read.  In C11 this has undefined behavior.  Use atomic_read.  The
> write side does not need atomic_set, because it is protected by a
> mutex.

Is tsan happy with the way seqlocks are written right now?

According to this message I just found by Dmitry Vyukov, tsan
shouldn't be. Note however that the message is from April'15,
so it might be outdated:

Dmitry Vyukov wrote:
> 1. Tsan is bad at handling stand-alone memory barriers. 
<snip>
> And here is a way to express seqlock that is both correct, is 
> understood by tsan and is no overhead on x86: 
> 
> // writer 
> atomic_store(&seq, seq+1, memory_order_relaxed); 
> atomic_store(&data[0], ..., memory_order_release); 
> ... 
> atomic_store(&data[N], ..., memory_order_release); 
> atomic_store(&seq, seq+1, memory_order_release); 
> 
> // reader 
> atomic_load(&seq, memory_order_acquire); 
> d0 = atomic_load(&data[0], memory_order_acquire); 
> ... 
> dN = atomic_load(&data[N], memory_order_acquire); 
> atomic_load(&seq, memory_order_relaxed); 

Source: https://groups.google.com/forum/#!topic/thread-sanitizer/B4i9EMQ4BQE

Thanks,

                Emilio



reply via email to

[Prev in Thread] Current Thread [Next in Thread]