Pregunta

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...

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top