> 
> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to