Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2455 Discussions

specifying comparator of concurrent_priority_queue in runtime


Is it possible to specify the comparator of tbb::concurrent_priority_queue in runtime, as in std::priority_queue?

In std::priority_queue, you can pass the comparator as an argument of the constructor. For example, see 'sixth' of the following example.

However, it seems like tbb::concurrent_priority_queue does not receive comparator as an argument, and creates one itself using the default constructor. Is there any way to specify it in runtime?

Hyokun Yun 

0 Kudos
2 Replies

It is correct that the comparator cannot be dynamically specified. We can take this as a feature request. In order to more clearly understand the decision, would you be able to share a bit more about what you would like to do with that ability? I.e. why is it importatnt, what's your use case?


0 Kudos
Black Belt

Two threads about the same subject: this must be important...

I've already officially submitted a possible contribution to address this (just a matter of introducing a new set of constructors).

BTW, the C++ templates that use comparators apparently store ((ordered) associative containers, priority_queue) or even accept (sorting and related operations) them only by value (do tell if I overlooked anything), not by reference, but I don't see a need to second-guess that in TBB. Not to say that it was the right choice, but if you're in control of what comparator class to use, there's always embedding as a workaround against object slicing, and otherwise I would be curious about a use case that would run into this general limitation.

0 Kudos