Page MenuHomeFreeBSD

Correct fences for sys/refcount.h
ClosedPublic

Authored by kib on Jun 19 2017, 9:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
May 30 2024, 12:30 PM
Unknown Object (File)
Apr 22 2024, 1:36 PM
Unknown Object (File)
Feb 6 2024, 11:06 AM
Unknown Object (File)
Jan 12 2024, 1:56 AM
Unknown Object (File)
Dec 20 2023, 10:42 PM
Unknown Object (File)
Dec 15 2023, 9:57 PM
Unknown Object (File)
Oct 30 2023, 5:30 AM
Unknown Object (File)
Sep 30 2023, 1:36 PM
Subscribers

Details

Summary

The acq barrier in refcount_acquire() has no use, constructor must ensure that the changes are visible before publication by other means.

Last release must sync/with the constructor and all updaters.

This is quite subtle and based on the refcount/shared_ptr analysis I heard at the Hans Boehm/ Herb Sutter talks about C++ atomics.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Jun 19 2017, 2:24 PM
sys/sys/refcount.h
69 ↗(On Diff #29809)

"destructing code" -> "destructor"

72 ↗(On Diff #29809)

It's unclear what "there" refers to.

kib marked an inline comment as done.Jun 19 2017, 3:30 PM
kib added inline comments.
sys/sys/refcount.h
72 ↗(On Diff #29809)

The claim is that the code for refcount_release() should look like this, using C11 operations:

int
refcount_release(volatile atomic_uint *count)
{
  int res;

   res = atomic_fetch_sub_explicit(count, 1, memory_order_acq_rel);
   return (res == 1);
}

The release operation in non-final refcount_release() calls which return false, sync/w the acquire operation on the final refcount_release() returning true. In other words, 'there' means the atomic_fetchadd_int op.

In fact, we can add atomic_fence_rel() before the atomic_fetchadd_int() line for the same effect.

kib edited edge metadata.

Provide the release fence in refcount_release(), instead of relying on user handling it correctly.

This revision now requires review to proceed.Jun 19 2017, 3:50 PM

Are the talk(s) you referenced the ones from cppcon?

edit: looks like this is covered in the last ~15 minutes of https://www.youtube.com/watch?v=M15UKpNlpeM

This revision is now accepted and ready to land.Jun 20 2017, 5:41 AM

Are the talk(s) you referenced the ones from cppcon?

edit: looks like this is covered in the last ~15 minutes of https://www.youtube.com/watch?v=M15UKpNlpeM

Yes, and Herb's talk from 2015.

Alan, are you fine with the latest variant of the patch ?

In D11270#235791, @kib wrote:

Alan, are you fine with the latest variant of the patch ?

I haven't had a chance to think about it in any depth. Give me until Friday.

alc added inline comments.
sys/sys/refcount.h
68 ↗(On Diff #29817)

"destructor" is misspelled.

This revision was automatically updated to reflect the committed changes.