• 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: Quincey Morris <email@hidden>
  • Date: Fri, 07 Oct 2016 21:22:08 -0700
  • Feedback-id: 167118m:167118agrif8a:167118s1y6_KlIuo:SMTPCORP

On Oct 7, 2016, at 21:06 , Gerriet M. Denkmann <email@hidden> wrote:
>
> But, alas, it is also much slower: overhead almost 40 sec (whereas my admittedly rather hackish way took less then half a second).

That may indicate a lot of contention — e.g. you were running multiple copies of that loop in different threads, and each loop was doing an increment every iteration. I’d actually try doing it this way:

> 	//	One-time initialization, globally
>
> 	dsema = dispatch_semaphore_create (1);
>
> 	NSUInteger counter = 0;
>
>
> 	//	Per-thread code, locally
>
> 	NSUInteger perThreadCounter = 0;
>
> 	for …
> 	{
> 		…
> 		perThreadCounter++;
> 	}
>
> 	dispatch_semaphore_wait (dsema, <forever>);
> 	counter += perThreadCounter;
> 	dispatch_semaphore_signal (dsema);

That should diminish the overhead to, effectively, zero.

But this is a bit academic, if you have a non-deprecated method of atomic incrementing available. This is about what you might do for a more complicated calculation that is not inherently atomic.



_______________________________________________

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: "Gerriet M. Denkmann" <email@hidden>
References: 
 >How to count Atoms (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to count Atoms (From: Quincey Morris <email@hidden>)
 >Re: How to count Atoms (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to count Atoms (From: Quincey Morris <email@hidden>)
 >Re: How to count Atoms (From: "Gerriet M. Denkmann" <email@hidden>)

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