Now I have a solver in that I need to keep a set of self-defined data type objects in a concurrent_vector or queue. It has to be concurrent because the objects come from different threads.With this concurrent container, I hope to sort these objects, eliminate duplicates and send them back when other threads need them.
However, I know TBB offers concurrent_vector and concurrent_queue which can be read and written concurrently from different threads. But how to sort the objects inside a container? Does everyone know how to do that? Thanks.
I guess the producer threads should run concurrently with the consumer threads. So if the elements would not need to be sorted and made unique a simple concurrent_queue would suffice.
If you only need to make them unique, you could use a
tbb::concurrent_hash_mapfor that.However, if you really want to have the elements sorted, you need something like a concurrent_set (ordered) which is rather complicated and does not exist in tbb. So if you really need to have those elements sorted, i would propose to use a simple lock which must be aquired for putting elements to your container (e.g. std::set) and for retrieving them out of it.