- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 trapIt almost looks like it called the destructor multiple times.
The code in question is at:
Any idea what could I be doing wrong?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page