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

Concurrent Queue from Herb Sutter article

laurentb
Beginner
222 Views
Hi,
Today was planing to implement Herbe Sutter article
http://www.ddj.com/hpc-high-performance-computing/212201163
using tbb::atomic, but tbb::atomic doesn't seems to support incomplete type.

How can I handle this issue ?

For example this kind of code doesn't compile
because Node is incomplete inside Node.

[cpp]#include "tbb/atomic.h"

struct Node
{
tbb::atomic ptr;
} Node;

int main(int argc, char *argv [])
{
Node nd;
return 0;
}[/cpp]


How do I fix this pb ? Do I have to split Node implementation from Node usage, like atomic itself.


0 Kudos
4 Replies
Alexey-Kukanov
Employee
222 Views
Just update toa more recent release of TBB. The problem has been addressed in TBB 2.1 Update 2.
0 Kudos
laurentb
Beginner
222 Views
Thanks you very much
Updating to the last version fix the pb
0 Kudos
Charles_Tucker
Beginner
222 Views
Just update toa more recent release of TBB. The problem has been addressed in TBB 2.1 Update 2.

Having not looked too closely at the most up-to-date code, how was this problem addressed? I'm curious how pointer-types are configured for increment/decrement operations without evaluating the size of the incomplete type.
0 Kudos
RafSchietekat
Black Belt
222 Views
"Having not looked too closely at the most up-to-date code, how was this problem addressed? I'm curious how pointer-types are configured for increment/decrement operations without evaluating the size of the incomplete type."
Template class member functions are instantiated just in time, and only then must all details be known. Previously, sizeof(T) was evaluated before inheriting common behaviour. I myself tried to solve the problem by not inheriting the operations, using macros instead to inject the operations at both the atomic hierarchy exit(s) and in the abstract subclass for further specialisation (where the increment value would always be 1). Apparently, tbb21_20090313oss instead inherits from a template based on T for atomic and char otherwise, thus avoiding to need to know sizeof(T) already, and inheritance does not force instantiation yet, so this also works. Nicely done!

(Added) Actually, I used #include for the injections, because the included file itself uses macros. Shiver!
0 Kudos
Reply