Question

What happens when I use OSSpinLockLock when the lock is already held in the same thread? (hence it should "let me in").

I know it doesn't have a counter, but it's a problem to implement one, because then I'd need to verify this is the thread, the count is zero, and all this would probably need to be locked as well...

Was it helpful?

Solution

If you attempt to lock a spin lock from the thread that already owns it, you will deadlock. Spin locks are not recursive.

You should either look at pthread recursive mutexes, or change your design to avoid having to lock recursively.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top