• 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
[SOLVED]RE: Thread and sleep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED]RE: Thread and sleep


  • Subject: [SOLVED]RE: Thread and sleep
  • From: "Peter Karlsson" <email@hidden>
  • Date: Wed, 19 Jan 2005 20:24:28 +0100

The problem was my wakeThread code. It took the value from the sender
(button) and that value was 1 and then 0 and then 1 and so on. I solved it
by setting the lock to 1 every time.

Peter

Ursprungligt meddelande

> This is what happens:
>
> First mouse click: (this button (button 1) starts the second thread)
> The second thread sleeps
>
> Second mouse click: (button 2)
> The second thread wakes up
> My code continues here
> The second thread sleeps
>
> Third mouse click: (button 2)
> The code for waking up second thread is called (wakeThread) but second
> thread does not wake up.
>
> Fourth mouse click: (button 2)
> The second thread wakes up
> My code continues here...
> Second thread exits here
>
> So the question is, why does the second thread not wake up on the third
> mouse click?
>
> Peter
>
> Ursprungligt meddelande
>
> > I have tested another way but that will not work either. This is what I
> did:
> >
> > I init my lock when my app starts up like this:
> >
> > lock = [[NSConditionLock alloc] initWithCondition:0];
> >
> > I wait for the button to be pressed in my second thread like this:
> >
> > [lock lockWhenCondition:1];
> > [lock unlockWithCondition:0];
> >
> > In my worker thread I call this action when I click the button:
> >
> > - (void)wakeThread:(id)sender
> > {
> > [lock lock];
> > [lock unlockWithCondition:[sender state]];
> > }
> >
> > My second thread sleeps until the button is pressed. But not the second
> > time. Can someone please tell me why?
> >
> > Peter
> >
> >
> > Ursprungligt meddelande
> >
> > > Dear list!
> > >
> > > I'm running a second thread and I want the thread to sleep until a
> > NSButton
> > > is pressed. Right now I'm checking the state of the button and if it's
> not
> > > pressed I sleep for a while and repeat everything until the button is
> > > pressed. Then the thread continue. Code fragment:
> > >
> > > while ([myButtonOutlet state] != 1)
> > > {
> > > usleep(100000);
> > > }
> > >
> > > But it seems that this will not work if I do it more then one time in
a
> > > row. I must click the button twice for some reason sometimes to make
the
> > > thread continue. I don't know why.
> > >
> > > Is there another and better way to do this?
> > >
> > > Best regards Peter
> > >
> > >  _______________________________________________
> > > Do not post admin requests to the list. They will be ignored.
> > > Cocoa-dev mailing list      (email@hidden)
> > > Help/Unsubscribe/Update your Subscription:
> > >
> > > This email sent to email@hidden
> > >
> >
> >  _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Cocoa-dev mailing list      (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> >
> > This email sent to email@hidden
> >
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Building a GUI for a command line tool.
  • Next by Date: NSURLConnection Certificate Problem
  • Previous by thread: Re: Finding out my document's extension
  • Next by thread: NSURLConnection Certificate Problem
  • Index(es):
    • Date
    • Thread