Can a pthread_mutex_t be moved in memory?

送分小仙女□ 提交于 2019-12-05 07:49:12

It's not safe to move mutexes. Some mutex implementations on Linux, for example, use the futex system call which specifically waits on the address of the mutex.

If it needs to grow dynamically, I'd suggest using a master array of pthread_mutex_t pointers and a mutex for that master list. When you grow the array, you will just be moving the list of pointers rather than the mutexes themselves. The mutexes can be allocated with plain malloc.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!