• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Threading Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threading Question


  • Subject: Re: Threading Question
  • From: Mark Pauley <email@hidden>
  • Date: Wed, 01 Feb 2012 09:56:11 -0800

Strange, man atomic works just fine with 10.7 / Xcode 4.2 over here.

Check out the online version at https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/OSAtomicAdd32.3.html

_Mark

On Feb 1, 2012, at 9:53 AM, Morgan Packard wrote:

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

References: 
 >Re: Threading Question (From: Morgan Packard <email@hidden>)

  • Prev by Date: Re: Threading Question
  • Next by Date: Re: Threading Question
  • Previous by thread: Re: Threading Question
  • Next by thread: Re: Threading Question
  • Index(es):
    • Date
    • Thread