0

I am working on iOS Core Audio following the suggestion from this post: Core Audio render thread and thread signalling.

In the updated answer, which uses dispatch_semaphore_t, I understand that I don't need to call dispatch_release when ARC is enabled after reading this post: Does ARC support dispatch queues?.

However, in the original answer when semaphore_t is used (see below code snippets), I cannot find reference for whether I need to destroy the semaphore by calling semaphore_destroy when ARC is enabled. Can someone please help?

semaphore_t mSemaphore;

kern_return_t result = semaphore_create(mach_task_self(), &mSemaphore, SYNC_POLICY_FIFO, 0);

// Do stuff with semaphore wait and signal ...

kern_return_t result = semaphore_destroy(mach_task_self(), mSemaphore);

Thank you in advance!

Datow King
  • 161
  • 5
  • 11

1 Answers1

0

Yes, you need to destroy Mach semaphores manually. ARC does not automatically manage Mach semaphores. And, by analogy with dispatch semaphores, if ARC did manage them, it would disallow the use of semaphore_destroy(). If it's not disallowing that, then you can and should use it.

Note that Mach semaphores are not reference counted. There are no retain and release operations, just create and destroy. There's no difference between a strong or unsafe unretained reference. All references are, effectively, unsafe unretained. Without reference counting, ARC can't reason about the semaphore objects as they are passed around through code.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154