On 12 Mar 2018, at 18:43, Sandor Szatmari <firstname.lastname@example.org> wrote:
On Mon, Mar 12, 2018 at 1:28 PM, Dave <email@example.com> wrote:
Hi Again Sandor,
Yes, I’ve had similar fun doing the same thing here!
Thanks for the heads up on isCancelled and I’ll take your advice and store it as a property.
I’m not sure I understand what you mean with the call to “wait” - please see code revised code below.
See below for what I'm talking about with the -wait call...
Additionally, think about where your testing -isCancelled and breaking out of the loop(s); you have multiple loops. Does that break, break you out of all loops or just the innermost loop. Do you want to break out of all loops... if your terminating the thread, probably.
Where you've placed it, It looks like you can remove an object from the queue and the break the loop without processing it... if the application were not terminating and you were going to resume processing, you would loose that one item...
You also might want to check it at the head of your loop... and/or check it before you call -wait inside my suggested loop... In general where and how often you check -isCanceled can determine how responsive and well behaved an app/thread is to terminating... Just be sure to make sure your leaving everything in an expected/sane state; tearing things down properly... releasing objects... unlocking your conditions... etc.
Yes, that is what is does in effect, the outer while loop is "while ([[NSThread currentThread] isCancelled] == NO)” which does the same thing.
It only processes the Object if there is one at the head of the queue, the act of getting the head item also removes it. For every “wait" it receives it may process more than one object before waiting again (e.g. it tries to drain the queue), this guards against over or under signalling. Also, it does use a “Boolean Predicate”, this this if the queue is empty or not, e.g. [array count] != 0, if there are no objects waiting to be processed then its False otherwise its True., I’ve been stress testing it and it stands up to everything I can throw at it, the worst case is we get choppy results under extreme circumstances. Basically think of a VERY precise volume control, these are a LOT of steps from no sound to full volume, but after that differences are small.
All the Best