tags:

views:

143

answers:

5

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

A: 

Standard C++ has no equivalent, as it has no concept of concurrency; without concurrency, such a structure is both useless and dangerous, as operating on it could potentially block forever if there are no other threads.

It would be easy to implement, however, but the implementation details would depend on the threading library you're using.

As a side note, the upcoming C++1x standard will add some basic threading features to the standard library.

dauphic
+2  A: 

Intel's Threading Building Blocks has a couple different concurrent queues, one of which might be similar.

ergosys
+3  A: 

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.

Jerry Coffin
+2  A: 

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).

ZoogieZork
+1  A: 

concurrent_queue might be the one you are looking for. It comes with Parallel Patterns library from Microsoft.

Jagannath