Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2421 Discussions

specifying comparator of concurrent_priority_queue in runtime

Hyokun_Y_
Beginner
106 Views

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.  http://www.cplusplus.com/reference/queue/priority_queue/priority_queue/

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?

Thanks,
Hyokun Yun 

0 Kudos
2 Replies
Jackson_M_Intel
Employee
106 Views

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?

Thanks.

RafSchietekat
Black Belt
106 Views

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.

Reply