Re: [PATCH v1 0/2] Add support for print exactly once

FUJITA Tomonori
2025-11-13T09:55:58Z

On Tue, 11 Nov 2025 17:35:04 -0800
Boqun Feng <boqun.feng@gmail.com> wrote:

> On Wed, Nov 12, 2025 at 10:18:53AM +0900, FUJITA Tomonori wrote:
> [..]
>> >>
>> >> I agree. I think that even if the type is (), a race condition would
>> >> still occur if the init member were reset to zero using non-atomic
>> >> operations. For instance, the as_ref() method effectively checks
>> >
>> > I already explained this, the debugfs writes have to be treated as
>> > per-byte atomic, otherwise it's data race, using "non-atomic" to
>> > reference that won't be accurate.
>>
>> Suppose the init member of SetOnce is set to 2 and then reset to 0 via
>> debugfs. In that case, if two threads execute the as_ref() method at
>> the same time, is it guaranteed that they will both see the same
>> value?
>
> No, but it's not because it's non-atomic, but because there is no
> synchronization in this case. It'll still be problem even if the reset
> is atomic.

Of source, I was using the term "atomic operations" in the way it's
used in the kernel docs (for example, in atomic_t.txt), namely to
refer to the set of functions that ultimately issue CPU atomic
instructions. Naturally, those perform the appropriate
synchronization.