Re: Threading Question
Re: Threading Question
- Subject: Re: Threading Question
- From: Morgan Packard <email@hidden>
- Date: Wed, 01 Feb 2012 12:53:30 -0500
What do I need to do to see this excellent manpage? "man atomic" in my terminal gives me nothing.
Morgans-MacBook-Pro:source morganpackard$ man atomic
No manual entry for atomic
thanks.
-Morgan
On Tue, Jan 31, 2012 at 7:50 PM, Mark Pauley
<email@hidden> wrote:
This is exactly what I'm talking about when I speak of the functions available for you in <libkern/OSAtomic.h>
For example: OSAtomicEnqueue and OSAtomicDequeue actually provide the non-blocking FIFO behavior described by previous responses.
From the Man Page:
> The routines OSAtomicEnqueue() and OSAtomicDequeue() operate on singly linked LIFO queues. Ie, a dequeue operation will return the most recently enqueued element, or NULL if the list is empty.
> The operations are lockless, and barriers are used as necessary to permit thread-safe access to the queue element. offset is the offset in bytes to the link field in the queue element. For
> example:
>
> typedef struct elem {
> long data1;
> struct elem *link;
> int data2;
> } elem_t;
>
> elem_t fred, mary, *p;
>
> OSQueueHead q = OS_ATOMIC_QUEUE_INIT;
>
> OSAtomicEnqueue( &q, &fred, offsetof(elem_t,link) );
> OSAtomicEnqueue( &q, &mary, offsetof(elem_t,link) );
>
> p = OSAtomicDequeue( &q, offsetof(elem_t,link) );
>
> In this example, the call of OSAtomicDequeue() will return a ptr to mary.
This uses an LIFO, which while it may cause problems (if your producers keep pace in lockstep with your consumers you will get starvation and out-of-order messages), probably will be just fine for you (since you probably drain the messages MUCH faster than you enqueue them on average). I would just use this API unless you can prove that the LIFO isn't cutting it.
again: RTEM (Read the Excellent Manpage) "man atomic" for further text and API to help you.
_Mark
On Jan 31, 2012, at 2:00 PM,
email@hidden wrote:
> <pedantic>
>
> Robert Bielik wrote:
> [...]
>>
>> void postMessageToFifo()
>> {
>
> (write barrier needed here)
>
>> ++fifoWritePtr;
>> }
>>
> [...]
>>
>> const Message* getMessageFromFifo()
>> {
>
> (read barrier needed here)
>
>> const Message* base = (const Message*)fifoQueue;
>> return base + (fifoReadPtr & 255);
>> }
>>
>
> </pedantic>
>
> _______________________________________________
> 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
_______________________________________________
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