I think I misunderstood your previous question, and consequently mis-answered. The lock should be declared outside of dispatch_apply, so that it's shared among all threads that call the block, but keep the lock/unlock should be in the block.