简体   繁体   中英

Can I use pthread mutex under GCD concurrency context

My function can be called concurrently by other's program using GCD. Can I lock resources by using pthread mutex?

Absolutely. At the end of the day, code running under GCD is just code running on a regular, old OS thread that just happens to be managed by GCD. As @Daniel points out, if you're using GCD throughout, you ought to use GCD's mechanisms for mutual exclusion (ie a serial queue), but if you're interoperating with legacy code that uses pthread mutexes to lock resources, you can certainly do that from within code executed by GCD as well.

我不确定我是否完全理解你的问题(如果你能附上代码会很有帮助),我建议阅读这篇短文 - gcd-queues-synchronization也许你可以确保该函数在同一个队列上运行( thread) 使用 GCD,它将解决您的同步问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM