These days I've been trying to learn how to work with threads. I've been trying different things and I believe that the boost library is my best option because expert programmers have done all the work.
==5009== HEAP SUMMARY:
==5009== in use at exit: 8 bytes in 1 blocks
==5009== total heap usage: 21 allocs, 20 frees, 1,965 bytes allocated
==5009==
==5009== 8 bytes in 1 blocks are still reachable in loss record 1 of 1
==5009== at 0x4023F50: malloc (vg_replace_malloc.c:236)
==5009== by 0x4042DDB: boost::detail::get_once_per_thread_epoch() (in /home/blue/Desktop/informatica/proyectos/biblioteca/libboost_thread.so.1.51.0)
==5009== by 0x403A5A4: T.1510 (in /home/blue/Desktop/informatica/proyectos/biblioteca/libboost_thread.so.1.51.0)
==5009== by 0x403A706: boost::detail::get_current_thread_data() (in /home/blue/Desktop/informatica/proyectos/biblioteca/libboost_thread.so.1.51.0)
==5009== by 0x4041654: boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*) (in /home/blue/Desktop/informatica/proyectos/biblioteca/libboost_thread.so.1.51.0)
==5009== by 0x4041FE9: boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) (in /home/blue/Desktop/informatica/proyectos/biblioteca/libboost_thread.so.1.51.0)
==5009== by 0x403C696: boost::thread::join() (in /home/blue/Desktop/informatica/proyectos/biblioteca/libboost_thread.so.1.51.0)
==5009== by 0x8050F4A: ??? (in /home/blue/Desktop/informatica/proyectos/biblioteca/app)
==5009== by 0x41C8CA5: (below main) (libc-start.c:228)
==5009==
==5009== LEAK SUMMARY:
==5009== definitely lost: 0 bytes in 0 blocks
==5009== indirectly lost: 0 bytes in 0 blocks
==5009== possibly lost: 0 bytes in 0 blocks
==5009== still reachable: 8 bytes in 1 blocks
==5009== suppressed: 0 bytes in 0 blocks
==5009==
==5009== For counts of detected and suppressed errors, rerun with: -v
==5009== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 27 from 6)
Thanks a lot for your answer. I couldn't find that in my searches.
I copy the answer from that post in case someone finds it useful.
Is that really a memory leak?
most likely not. the memory in question is freed by a deleter of
pthread_key_create, which means when the (main) thread is exited.
valgrind apparently does the leak checking before that.
Stefan Strasser-2
Thanks a lot for your help, it was really useful.
PS: Increasing the number of threads doesn't increase the amount of memory leaked.