今天在解决客户的一个内存泄露的问题,客户提供了source code,但从代码语法,代码结构上的检查,都没有发现什么问题,编码风格还算整洁,那为什么还有Memory Leak?
客户代码有一个特点,使用了多线程,而且用得还比较频繁,而且初看代码,也没有问题,线和有创建pthread_create, 都会有退出pthread_exit,那问题在那里,于是,就查看了下linux的api手册,仔细研究了下linux 的thread.
##Linux如此说
A thread may either be joinable or detached. If a thread is joinable, then another thread can call
pthread_join(3) to wait for the thread to terminate and fetch its exit status. Only when a terminated joinable
thread has been joined are the last of its resources released back to the system. When a detached thread termi‐
nates, its resources are automatically released back to the system: it is not possible to join with the thread in
order to obtain its exit status. Making a thread detached is useful for some types of daemon threads whose exit