• 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: How to count Atoms
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to count Atoms


  • Subject: Re: How to count Atoms
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Fri, 07 Oct 2016 21:49:50 +0700

> On 7 Oct 2016, at 15:14, Quincey Morris <email@hidden> wrote:
>
> On Oct 7, 2016, at 00:19 , Gerriet M. Denkmann <email@hidden> wrote:
>>
>> So what is the proper way to count something atomicly and undeprecatedly?
>
> One straightforward way is to use dispatch_semaphore. IIRC it’s lightweight unless it blocks (that is, unless its count is zero when you wait), so it’s good for this situation where actual contention is rare (assuming actual contention is rare).

Is there a better way than this:
dsema = dispatch_semaphore_create( 0 );

some loop to be counted
{
	dispatch_semaphore_signal(dsema);
	….
}

NSUInteger counter = 0;
for(;;)
{
	long a = dispatch_semaphore_wait(dsema, DISPATCH_TIME_NOW);
	if ( a != 0 ) break;
	counter++;
};

Anyway: to count 20 mio things takes an overhead of ca. 0.5 sec for all of:
OSAtomicIncrement32 — deprecated in macOS 12
atomic_fetch_add_explicit
dispatch_semaphore_signal

IncrementAtomic— deprecated in macOS 8 has overhead of 2.7 sec

> If performance is not a consideration, you can use @synchronized instead. It’s marginally easier to use.

Here the overhead is 2 minutes = 240 times the other counting methods.
Performance is not a consideration, but this is just too much.

Thanks for your help!

Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How to count Atoms
      • From: Quincey Morris <email@hidden>
References: 
 >How to count Atoms (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to count Atoms (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: How to count Atoms
  • Next by Date: Logging in macOS 12
  • Previous by thread: Re: How to count Atoms
  • Next by thread: Re: How to count Atoms
  • Index(es):
    • Date
    • Thread