Git Product home page Git Product logo

Comments (2)

Darksonn avatar Darksonn commented on July 18, 2024 1

All of the codepaths you have pointed out are reachable only when the vtable is SHARED_VTABLE. However, when this is the case, the data field is immutable and never modified. Therefore, relaxed is enough. In fact, a non-atomic load would have been enough.

To see this, note that the data pointer is only changed in one location:

bytes/src/bytes.rs

Lines 1157 to 1166 in 74e6e20

// Try compare & swapping the pointer into the `arc` field.
// `Release` is used synchronize with other threads that
// will load the `arc` field.
//
// If the `compare_exchange` fails, then the thread lost the
// race to promote the buffer to shared. The `Acquire`
// ordering will synchronize with the `compare_exchange`
// that happened in the other thread and the `Shared`
// pointed to by `actual` will be visible.
match atom.compare_exchange(ptr as _, shared as _, Ordering::AcqRel, Ordering::Acquire) {

However, that line of code is only callable on a Bytes or BytesMut if the vtable is PROMOTABLE_EVEN_VTABLE or PROMOTABLE_ODD_VTABLE.

from bytes.

wang384670111 avatar wang384670111 commented on July 18, 2024

All of the codepaths you have pointed out are reachable only when the vtable is SHARED_VTABLE. However, when this is the case, the data field is immutable and never modified. Therefore, relaxed is enough. In fact, a non-atomic load would have been enough.

To see this, note that the data pointer is only changed in one location:

bytes/src/bytes.rs

Lines 1157 to 1166 in 74e6e20

// Try compare & swapping the pointer into the `arc` field.
// `Release` is used synchronize with other threads that
// will load the `arc` field.
//
// If the `compare_exchange` fails, then the thread lost the
// race to promote the buffer to shared. The `Acquire`
// ordering will synchronize with the `compare_exchange`
// that happened in the other thread and the `Shared`
// pointed to by `actual` will be visible.
match atom.compare_exchange(ptr as _, shared as _, Ordering::AcqRel, Ordering::Acquire) {

However, that line of code is only callable on a Bytes or BytesMut if the vtable is PROMOTABLE_EVEN_VTABLE or PROMOTABLE_ODD_VTABLE.

I understand the code now. Using Relaxed here works fine. Thank you for your response.

from bytes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.