Re: Threading Question
Re: Threading Question
- Subject: Re: Threading Question
- From: Morgan Packard <email@hidden>
- Date: Sun, 12 Feb 2012 20:55:08 -0500
I'd be very grateful for a ring buffer I can trust for communication from one thread to another.
-Morgan
On Sun, Feb 12, 2012 at 8:08 PM,
<email@hidden> wrote:
Michael Tyson wrote:
> Incidentally, I dunno if this is helpful, but I thought I'd chime in:
I've
> got a lock-free ring buffer implementation, TPCircularBuffer
> (
https://github.com/michaeltyson/TPCircularBuffer) which might do the
> trick for this. It uses atomic operations and a memory barrier, and
works
> with one reader and one writer. It's based on some neat VM stuff that
> wraps the memory space around so the memory wrapping is transparent.
The code linked to does not have any memory barriers at all. There is
nothing stopping writes from the memcpy (in
TPCircularBufferProduceBytes) being reordered (by the CPU) such that
they become visible after the OSAtomicAdd32 (in
TPCircularBufferProduce). There needs to be a write barrier after the
memcpy in order to be safe.
Similarly, the memory barrier on read is missing too - this is needed
between copying fillCount in to availableBytes (in TPCircularBufferTail)
and returning from TPCircularBufferTail.
> It's not been formally proven to be correct, but I'm pretty sure it's
> right, and I've never had any issues with it.
Note that this problem won't show up on older iOS devices (since they
are single core) nor on x86 (which is quite strongly ordered). However,
you will likely see issues on the iPad 2 and iPhone 5.
Cheers,
Michael
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (
email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to
email@hidden
--
===============
Morgan Packard
cell: (720) 891-0122
aim: mpackardatwork
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden