May I know is there any C++ equivalent class, to Java java.util.concurrent.ArrayBlockingQueue
http://download.java.net/jdk7/docs/api/java/util/concurrent/ArrayBlockingQueue.html
Check out tbb::concurrent_bounded_queue from the Intel Threading Building Blocks (TBB).
(Disclaimer: I haven't actually had a chance to use it in a project yet, but I've been following TBB).
The current version of C++ doesn't include anything equivalent (it doesn't include any thread support at all). The next version of C++ (C++0x) doesn't include a direct equivalent either.
Instead, it has both lower level constructs from which you could create a thread safe blocking queue (e.g. a normal container along with mutexes, condition variables, etc., to synchronize access to it).
It also has a much higher level set of constructs: a promise
, a future
, a packaged_task
, and so on. These completely hide the relatively low level details like queuing between the threads. Instead, you basically just ask for something to be done, and sometime later you can get a result. All the details in between are handled internally.
If you want something right now, you might consider the Boost Interprocess library. This includes (among other things) a Message Queue class. If memory serves, it supports both blocking and non-blocking variants.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With