Hey folks,

I have a worker thread that is only slowly polling. I would like to be
able wake him up from a different thread though. A bit like the
select(2) pattern. So what I do is:

...

    pollingCondition = [[NSCondition alloc] init];

...

    - (void) pollNow
    {
        [pollingCondition lock];
        [pollingCondition signal];
        [pollingCondition unlock];
    }

    - (void) workerThread:(id)arg
        ...
        while (!quit) {

            [pollingCondition lock];
            [pollingCondition waitUntilDate: [NSDate
dateWithTimeIntervalSinceNow:SLEEP]];
            [pollingCondition unlock];

            ...
        }
        ...
    }

Is it OK to do it like that? Is there a better way?

I've seen an "unlocked when not locked" and don't understand how this
could happen.

cheers
--
Torsten
_______________________________________________

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

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

Reply via email to