• 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: Dave Fernandes <email@hidden>
  • Date: Fri, 07 Oct 2016 18:37:15 -0400

>
> In practice, you’d actually initialize the semaphore like this:
>
>> 	dsema = dispatch_semaphore_create (0); // start with a zero count
>> 	dispatch_semaphore_signal (dsema); // increment to the number of resources in the pool.
>
> That’s because if you create the semaphore with a non-zero count, then later try to release the semaphore object when its count is something different (which can happen if you have a more complex loop that you break out of), your app will crash. The API design assumption is that if you didn’t free all the original resources, your app has a bug (which I happen to think is bogus reasoning, but anyway…).

Wow, I’ve never come across that issue. But I don’t see how incrementing it after creating it is any different from creating it with a non-zero count. Either way, if you have resources available, the count will be non-zero, and you will crash if you try to deallocate. But I’m somewhat sure I’ve never seen a crash like that. Maybe I was just lucky?
_______________________________________________

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

  • Prev by Date: Re: Directory enumeration gives wrong file type for aliases
  • Next by Date: Re: Directory enumeration gives wrong file type for aliases
  • Previous by thread: Re: How to count Atoms
  • Next by thread: Re: How to count Atoms
  • Index(es):
    • Date
    • Thread