How to pause an NSThread until notified?

Look into NSCondition and the Conditions section in the Threading guide. The code will look something like:

NSCondition* condition; // initialize and release this is your app requires.

//Worker thread:
while([NSThread currentThread] isCancelled] == NO)
{
    [condition lock];
    while(partySuppliesAvailable == NO)
    {
        [condition wait];
    }

    // party!

    partySuppliesAvailable = NO;
    [condition unlock];
}

//Main thread:
[condition lock];
// Get party supplies
partySuppliesAvailable = YES;
[condition signal];
[condition unlock];

Leave a Comment