Giter VIP home page Giter VIP logo

Comments (4)

MengRao avatar MengRao commented on June 9, 2024 2

Those asm should only work for X86 platforms, you can think them as a light-weighed version of std::atomic_thread_fence(memory_order_relaxed), becasue x86 has strong memory-order so acquire/release is no different from relaxed.
The main overhead of the general compile-level memory fence(i.e. atomic_thread_fence(memory_order_relaxed)) is that data cached in registers needs to be stored to memory(in case other thread need to read) and then loaded from memory(in case other thread has written it), and compile can't tell what data can be accessed by other threads then it'll be the most conservative.
In using the asms, we explicitly tell the compiler what data can be written or read by the others, so it can do a little optimization(so I call it light-weighted memory fence).
Being said that, from benchmark result I didn't see notable performance difference between asms and std::atomic/memory fence, so I switched to std::atomic as it's more readable and cross-platform.

from spsc_queue.

MengRao avatar MengRao commented on June 9, 2024 1

I've replaced those asm statements with std::atomic to make it cross-platform and performance should be the same. Thanks.

from spsc_queue.

FloatingUpstream avatar FloatingUpstream commented on June 9, 2024

Many thanks for your response. But I was actually not sure if the asm volatile instruction is enough, and was trying to understand if it is sufficient in this case / what the rational behind it is. :)

from spsc_queue.

FloatingUpstream avatar FloatingUpstream commented on June 9, 2024

Thanks for the explanation :-)

from spsc_queue.

Related Issues (4)

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.