Comments (3)
There is a blocking version of the queue (added not too long ago) that will make your job easier -- it handles all the blocking on dequeue using a lightweight semaphore (fast when the queue still has items, and doesn't spin-wait forever when it's empty). It doesn't have any blocking enqueue operations, though (that may be an interesting feature to add, though -- I'll have to think about it more).
As for enumerating the contents, I'm afraid that's far more tricky. Even under the assumption that all other threads are stopped, it's entirely possible that the memory effects of operations done on those threads are not yet propagated to the CPU core on which the GC thread is running, which means items might be "missed" even if they're actually logically in the queue. It depends on how the other threads are paused -- there would have to be a memory barrier just before pausing that release all changes to the GC thread, and the GC thread would need a corresponding memory barrier after that point to acquire all those changes.
from concurrentqueue.
The world stop operation I use has a flag which is checked under a mutex which acts as a full barrier. It's a cooperative stop. Which is rather unfortunate.
However I have to back off my original need for blocking enqueue and dequeue. I have a queue already that does that (and allows enumerating all elements). I also have monitors. I'm using blocking condition variables/semaphores. Unfortunately that leads to a deadlock so I'm right now having to change all blocking operations to used timed waits that loop around and also check the world stop flag.
When a thread stops, it does a setjump() to save all the registers on the stack and then it saves its stack to a control object so the GC can scan all the thread stacks as roots.
With heavy trickery on some OS better can be done but its hard to provide a portable GC whilst still using C/C++ and OS native operations (Posix/Linux, OSX, Windows at least). OTOH any language without a GC is screwed.
from concurrentqueue.
I'm continuing to maintain the queue but at this point will not be adding any new features.
from concurrentqueue.
Related Issues (20)
- Memory Leak HOT 6
- [feature-request] Associating ProducerToken & ConsumerToken explicitly
- segment fault
- Occasionally program can be stuck inside try_dequeue of blockingconcurrentqueue.h HOT 1
- installed concurrentqueue using vcpkg, but can not make.
- try_dequeue_bulk core dump. HOT 2
- Introducing LIFO semaphore
- Waiting without dequeuing HOT 1
- ConcurrentQueue ~150x slower on Windows HOT 11
- Naming conflict HOT 2
- About license HOT 1
- Weird dequeue behavior HOT 8
- Linux fs.h causes compilation problems HOT 4
- To use one concurrent queue between multiple threads HOT 3
- GLIBC version requires 2.30, but deploy platform has 2.29 only
- try_enqueue takes up to 1024 elements, regardless of initial capacity HOT 4
- wait_dequeue occasionally not working properly HOT 5
- q.try_dequeue(...) Get exception EXC_BAD_ACCESS (code=1, address=0x0) HOT 1
- Dequeue a list using an std::vector HOT 1
- How to use Concurrent queue with std::vector HOT 1
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 concurrentqueue.