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

Boqun Feng
2025-11-12T01:35:07Z

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.

(I was distracted by the mentioning of "non-atomic" and didn't see the
real idea here...)

Regards,
Boqun