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

TBB destructor grief

clusty
Beginner
106 Views
Hey,
I just wrote my first tiny TBB test program using parallel_for and noticed that there is something fishy going on: if I try to do the cleanup on the class that implemets the blocked_range operator, it chokes with this error message:
cpuMandel_tbb(10532,0x7fff700b8ca0) malloc: *** error for object 0x100300000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap
cpuMandel_tbb(10532,0x7fff700b8ca0) malloc: *** error for object 0x100300000: pointer being freed was not allocated*** set a breakpoint in malloc_error_break to debugAbort trap
It almost looks like it called the destructor multiple times.
The code in question is at:
Any idea what could I be doing wrong?
0 Kudos
1 Reply
Alexey_K_Intel3
Employee
106 Views
Indeed the destructor is called multiple times, as parallel_for copies the body object passed to it, by using a copy constructor. You did not provide such a constructor explicitly,in which case the C++ standard requires it is created implicitly by compilers.It's highly likely that this implicit constructor simply does a bitwise-identical copy, so you end up with multiple instances holding the same pointer to the dynamically allocated buffer and deleting it in the destructor.
Reply