Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homegrown workqueue vs Intel TBB

We are considering which parallel framework for C/C++ to use. We have some very special conditions and are not 100% sure, that e.g. TBB can add something "more".

  • There are N running threads and one synchronized workqueue (using pthread mutex).
  • Our jobs are prioritized (int).
  • Jobs are put into the queue and idle thread takes a job with the highest priority.

This repeats until the queue is empty.

Well, and now, I'd like to know if some framework like TBB (Thread Building Blocks) can offer more for this special scenario from the algorithmic point of view?? (So, internals...)

like image 731
Cartesius00 Avatar asked Dec 05 '11 14:12

Cartesius00


2 Answers

TBB 4 provides a concurrent_priority_queue (search 'priority' in the reference manual). Furthermore, using TBB is nice if you can design your program with tasks, not threads, in mind. Indeed, it provides a lot of stuff to describe dependancies between tasks. Also, TBB seems to be fairly portable if it's important for you.

like image 77
Alexandre Hamez Avatar answered Oct 04 '22 20:10

Alexandre Hamez


In my opinion you could gain by replacing the heavy mutex with something more robust, like the spin_rw_mutex: http://threadingbuildingblocks.org/files/documentation/a00163.html. Since most likely insertion/removal operations are fast, you could benefit more from a non-blocking lock.

like image 21
Tudor Avatar answered Oct 04 '22 20:10

Tudor