04-17-2011 03:18 PM
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 trapcpuMandel_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?
04-18-2011 06:51 AM
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.