Re: How to count Atoms
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