[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3f740262-821b-4f39-8f1a-c6d02253986c@paulmck-laptop>
Date: Tue, 4 Jul 2023 14:25:09 -0700
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Alan Stern <stern@...land.harvard.edu>
Cc: Olivier Dion <odion@...icios.com>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
rnk@...gle.com, Andrea Parri <parri.andrea@...il.com>,
Will Deacon <will@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Boqun Feng <boqun.feng@...il.com>,
Nicholas Piggin <npiggin@...il.com>,
David Howells <dhowells@...hat.com>,
Jade Alglave <j.alglave@....ac.uk>,
Luc Maranget <luc.maranget@...ia.fr>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Tom Rix <trix@...hat.com>, linux-kernel@...r.kernel.org,
linux-arch@...r.kernel.org, gcc@....gnu.org, llvm@...ts.linux.dev
Subject: Re: [RFC] Bridging the gap between the Linux Kernel Memory
Consistency Model (LKMM) and C11/C++11 atomics
On Tue, Jul 04, 2023 at 04:25:45PM -0400, Alan Stern wrote:
> On Tue, Jul 04, 2023 at 01:19:23PM -0400, Olivier Dion wrote:
[ . . . ]
> > I am puzzled by this. Initialization of a shared variable does not need
> > to be atomic until its publication. Could you expand on this?
>
> In the kernel, I believe it sometimes happens that an atomic variable
> may be published before it is initialized. (If that's wrong, Paul or
> Peter can correct me.) But since this doesn't apply to the situations
> you're concerned with, you can forget I mentioned it.
Both use cases exist.
A global atomic is implicitly published at compile time. If the desired
initial value is not known until multiple threads are running, then it
is necessary to be careful. Hence double-check locking and its various
replacements. (Clearly, if you can determine the initial value before
going multithreaded, life is simpler.)
And dynamically allocated or on-stack storage is the other case, where
there is a point in time when the storage is private even after multiple
threads are running.
Or am I missing the point?
Thanx, Paul
Powered by blists - more mailing lists