Bugger. Yep. You’re both absolutely right. And sure enough, neither dispatch 
semaphores nor mach semaphores, nor condition variables are safe. All use locks 
of one form or another.

For the record:

- Dispatch semaphores (dispatch_semaphore_signal) are actually built upon mach 
semaphores (https://goo.gl/6nbU9C - search for _dispatch_semaphore_signal_slow, 
you’ll see semaphore_signal)
- Mach semaphores (semaphore_signal) use a lock (https://goo.gl/enxiiT - search 
for semaphore_signal_internal) - specifically, semaphore_signal calls 
semaphore_lock calls wait_queue_lock which has a platform-dependent 
implementation; a spin lock on i386 (no source available for arm).
- pthread_cond_signal also uses a lock (https://goo.gl/wpFz1k - search 
_pthread_cond_signal) - _pthread_cond_signal calls __psynch_cvsignal 
https://goo.gl/nCx6LC calls ksyn_wqlock calls lck_mtx_lock which is in 
xnu/osfmk and has a platform-dependent implementation, no arm source. For 
broadcast signalling: rather than __psynch_cvsignal, __psynch_cvbroad is 
called, but there the trail goes cold - it appears to be a system call. Closest 
I could find was _psynch_cvbroad at https://goo.gl/nCx6LC which calls 
__psynch_cvsignal again.

I guess either the folks that made CAGuard/AUAudioFilePlayer don’t know or 
don’t care, or know something I don’t about it being okay to use locks on the 
realtime thread =)

Would love a comment from someone in Core Audio.

Anyway - any other thoughts, before I convert my code back to using main thread 
polling? Am I being too precious about this? Have I been wrong the whole time, 
and locks are actually fine in this context?

--
Michael Tyson | atastypixel.com

Loopy: Record, loop, layer. Like a pro.
http://loopyapp.com

> On 24 May 2016, at 09:19, Ross Bencina <[email protected]> wrote:
> 
> On 24/05/2016 1:37 AM, Paul Davis wrote:
>> Unless you know the author of an email works inside Apple in a highly
>> technical role, I would advise against staking too much faith in a
>> comment like "or better yet dispatch semaphores". And someone who
>> doesn't know what POSIX semaphores are is doubly unlikely to be the
>> right person to take advice from on this matter.
> 
> I have a similar feeling. I'd go further and suggest that even if a highly 
> knowledgeable person said something in the past, it should not be taken as a 
> binding contract that OS X will continue to behave in a certain way.
> 
> @Michael Tyson: As far as I know, all of the relevant layers are open-source 
> (pthreads, libdispatch, kernel). It's worth taking at least a cursory glance 
> at the source code for the functions that you're interested in.
> 
> http://opensource.apple.com/
> 
> (For a while, pthreads source code was omitted. I haven't checked lately, you 
> may have to look at older releases to find it.)
> 
> Cheers,
> 
> Ross.
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/coreaudio-api/michael%40atastypixel.com
> 
> This email sent to [email protected]

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to