我有一个内存泄漏,只有在我使用 OpenMP 支持和 GNU Parallel 扩展进行编译时才会出现:-fopenmp -DGLIBCXX_PARALLEL
.
例子 :
std::transform(buffer, buffer + _tabLength, _origData, MathUtil::ShortToDouble);
结果(对 valgrind 模板的恐惧感到抱歉):
==7109== 912 bytes in 3 blocks are possibly lost in loss record 3 of 4
==7109== at 0x4C29C64: calloc (vg_replace_malloc.c:593)
==7109== by 0x4010F29: allocate_dtv (dl-tls.c:296)
==7109== by 0x401163D: _dl_allocate_tls (dl-tls.c:460)
==7109== by 0x5C505B8: pthread_create@@GLIBC_2.2.5 (allocatestack.c:579)
==7109== by 0x582D1C5: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
==7109== by 0x4309DB: double (*__gnu_parallel::__for_each_template_random_access_workstealing<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag>, double (*)(short), __gnu_parallel::__transform1_selector<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag> >, __gnu_parallel::_DummyReduct, bool>(__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag>, __gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag>, double (*)(short), __gnu_parallel::__transform1_selector<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag> >&, __gnu_parallel::_DummyReduct, bool, bool&, std::iterator_traits<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag> >::difference_type))(short) (workstealing.h:139)
==7109== by 0x42F6C8: double (*__gnu_parallel::__for_each_template_random_access<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag>, double (*)(short), __gnu_parallel::__transform1_selector<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag> >, __gnu_parallel::_DummyReduct, bool>(__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag>, __gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag>, double (*)(short), __gnu_parallel::__transform1_selector<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag> >&, __gnu_parallel::_DummyReduct, bool, bool&, std::iterator_traits<__gnu_parallel::_IteratorPair<short*, double*, std::random_access_iterator_tag> >::difference_type, __gnu_parallel::_Parallelism))(short) (for_each.h:86)
==7109== by 0x42EAF3: double* std::__parallel::__transform1_switch<short*, double*, double (*)(short)>(short*, short*, double*, double (*)(short), std::random_access_iterator_tag, std::random_access_iterator_tag, __gnu_parallel::_Parallelism) (algo.h:1240)
==7109== by 0x42E329: double* std::__parallel::transform<short*, double*, double (*)(short)>(short*, short*, double*, double (*)(short)) (algo.h:1293)
知道如何解决这个问题吗?