Comments (5)
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.
Many thanks for the explanation.
I guess I am out of luck in that case (especially targeting x64 and ARM). :-)
from readerwriterqueue.
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.
Not with shared memory, no.
from readerwriterqueue.
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)
- Circular Buffer force_enque HOT 5
- some questions HOT 3
- Queue as member variable breaks my program HOT 2
- Any way to copy a string into an element atomically? HOT 4
- Please add to README how to run tests HOT 1
- On an M1 on MacOS, when profiling with Tracy, ReadWriterQueue's try_enqueue / try_dequeue sometimes seem to cause spikes of several milliseconds HOT 6
- Deadlock with readerwriterqueue when spinning over try_enqueue() method HOT 1
- peek() method for BlockingReaderWriterCircularBuffer? HOT 4
- Circular Buffer Doesn't Overwrite Old Data HOT 2
- Help with profiling OSX M1 HOT 17
- Any plan on latest release tag HOT 2
- Memory allocation HOT 2
- Upload stable release archive HOT 1
- same content poped when queue should be empty HOT 1
- Is Runtime Allocation Possible HOT 2
- Supported platforms/operating systems? HOT 3
- Assertion `!inSection && "Concurrent (or re-entrant) enqueue or dequeue operation detected (only one thread at a time may hold the producer or consumer role) HOT 1
- Segfault when attempting to peek() into the queue std::__atomic_base<bool>::load (__m=std::memory_order_relaxed, HOT 2
- Folly's LockFreeRingBuffer HOT 2
- can i use readwritequeue? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from readerwriterqueue.