Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Equivalent java.util.concurrent.ArrayBlockingQueue

Tags:

java

c++

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

like image 931
Cheok Yan Cheng Avatar asked Dec 10 '22 17:12

Cheok Yan Cheng


2 Answers

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

like image 71
ZoogieZork Avatar answered Dec 19 '22 09:12

ZoogieZork


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.

like image 23
Jerry Coffin Avatar answered Dec 19 '22 07:12

Jerry Coffin