Giter Site home page Giter Site logo

Comments (5)

cameron314 avatar cameron314 commented on June 11, 2024 1

Shared memory is not covered by the C++ standard (it's completely platform-dependent).

Setting that aside (even if the shared memory behaves "as expected" on your target platform and you're willing to accept the risk of undefined behaviour), the queue relies in part on thread-local addresses/IDs for implicit producers, which breaks when multiple processes are involved.

My queue also allocates memory dynamically, so you'd need to plug in a special malloc/free implementation via its traits to even attempt to use it between processes.

The blocking version uses various platform-specific semaphore primitives, some of which are not safe to place and manipulate in shared memory. On Linux, it appears that POSIX semaphores (used by the queue for that platform) are actually supported in shared memory between processes, but 1 needs to be passed to sem_init to enable this feature (currently 0 is passed since this presumably has a cost).

So in short, it could work if you try hard enough (and avoid implicit producers, blocking, and possibly other features), but there's no guarantee that it wouldn't break arbitrarily some day, and it's outside the scope of this project to support it.

from readerwriterqueue.

FloatingUpstream avatar FloatingUpstream commented on June 11, 2024 1

Many thanks for the explanation.
I guess I am out of luck in that case (especially targeting x64 and ARM). :-)

from readerwriterqueue.

cameron314 avatar cameron314 commented on June 11, 2024 1

Oops, mixed up which repo this is -- readerwriterqueue does not use thread-local addresses/IDs, but the rest still applies. (Although there are no traits to override malloc/free.)

from readerwriterqueue.

cameron314 avatar cameron314 commented on June 11, 2024

Not with shared memory, no.

from readerwriterqueue.

FloatingUpstream avatar FloatingUpstream commented on June 11, 2024

May I ask what the issue in the case of shared memory is?
My unerstanding: std::atomic is only going to work in a single process, just as _mm_mfence, etc.

How does Boost's spsc_queue solve this in combination with shared memory?
https://stackoverflow.com/questions/22207546/shared-memory-ipc-synchronization-lock-free/22209595#22209595

As far as I can tell, it will usually just default to std::atomic and memory_* orderings as well? Is the stackoverflow thread simply wrong?

Thanks for any clarifiation!

from readerwriterqueue.

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.