• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSCondition (unlocked when not locked)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCondition (unlocked when not locked)


  • Subject: NSCondition (unlocked when not locked)
  • From: Torsten Curdt <email@hidden>
  • Date: Fri, 10 Jul 2009 13:50:00 +0200

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 (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

  • Follow-Ups:
    • Re: NSCondition (unlocked when not locked)
      • From: Benjamin Stiglitz <email@hidden>
  • Prev by Date: Re: Wake computer from sleep
  • Next by Date: How to write ipeg image created with CGImageRef?
  • Previous by thread: Re: Retain cycles with NIB instantiations, bindings
  • Next by thread: Re: NSCondition (unlocked when not locked)
  • Index(es):
    • Date
    • Thread