当前位置:编程学习 > C/C++ >>

调用pthread_mutex_destroy之后是否需要free

假设我有以下代码来初始化互斥变量:
[cpp]  
pthread_mutex_t *m = new pthread_mutex_t;  
pthread_mutex_init(m, NULL);  
使用结束后调用:
[cpp]  
pthread_mutex_destroy(m);  
那么我是否需要调用 free(m)
答:
你需要释放内存,pthread_mutex_destroy并不能为你释放。
为什么呢?
因为下面的调用方法是被允许的:
[cpp] 
pthread_mutex_t m;  
pthread_mutex_init(&m, NULL);  
  
pthread_mutex_destroy(&m); /* Can't free &m. 这里是引用*/  
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,