Reputation: 445
My function can be called concurrently by other‘s program using GCD. Can I lock resources by using pthread mutex?
Upvotes: 0
Views: 140
Reputation: 1686
I'm not sure I understand your question fully (if you can attach code it will be very helpful), I suggest reading this short post -gcd-queues-synchronization Maybe you can make sure that the function is running on the same queue (thread) using GCD and it will solve your synchronization problem.
Upvotes: 0
Reputation: 29926
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 (i.e. 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.
Upvotes: 1