Siy*_*Ren 0 c++ multithreading pthreads
假设我使用
pthread_mutex_t *m = new pthread_mutex_t;
pthread_mutex_init(m, NULL);
Run Code Online (Sandbox Code Playgroud)
初始化互斥锁.在我完成之后,调用pthread_mutex_destroy,我是否需要使用
delete m;
Run Code Online (Sandbox Code Playgroud)
释放所有资源?
你需要释放内存,因为pthread_mutex_destroy无法为你做到这一点.
为什么pthread_mutex_destroy没有为你释放内存?因为你被允许这样做:
pthread_mutex_t m;
pthread_mutex_init(&m, NULL);
pthread_mutex_destroy(&m); /* Can't free &m. */
Run Code Online (Sandbox Code Playgroud)
你可以尝试使用valgrind:
==836== LEAK SUMMARY:
==836== definitely lost: 24 bytes in 1 blocks
Run Code Online (Sandbox Code Playgroud)