• 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
Re: How can I stop running loop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I stop running loop?


  • Subject: Re: How can I stop running loop?
  • From: Mai Bui <email@hidden>
  • Date: Wed, 1 Dec 2004 20:48:23 -0800

Thanks a lot Shawn.

I think you did not get my reply, so I resend it now.
To answer your questions:
1. It acquire acoustic data (temp, density, conductivity, etc...)
2. These data are fed to serial port and my application reads them from it constantly. No block neither poll.

I wrote a small test. It has "stop" and "run" button (NSButton). The user will click on "run", it will create 2 thread (run, stop). For test, in run() has a while loop. In stop(), if the user click on it. It will turn the Doneflag on which is invoke later from run, it will stop app. But.... I do not know how to check the status of this stop button.

Can you or someone give me a hint?
Thanks in advance.

I attach my code along here.

@implementation StopApp

- (id)init
{
[super init];
stopState = false;
NSLog(@"Init\n");
return self;
}

- (id)sender
{
[sender setEnabled:NO]; // disable the run button
[stopBut setEnabled:YES]; // enable the stop button

runThread = [NSThread currentThread];
[NSThread detachNewThreadSelector: @selector(runLoop) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector: @selector(stopLoop) toTarget:self withObject:nil];
NSLog(@"Status: %d",[NSThread isMultiThreaded]);
NSLog(@"Press run button...\n");
// [runThread exit];
[sender setEnabled:YES]; // enable the run button
[stopBut setEnabled:NO]; // disable the stop button
}

//(void) RunLoop(NSTextView* statusText)
//- (void) runLoop:(id)object
- (void) runLoop
{
int i;
NSAutoreleasePool *runPtr = [[NSAutoreleasePool alloc] init];
// NSString *str = @"print out the string\n";
// Acquire data here, but run a dump in while loop for now ....
for (i=0; i<5000; i++)
{
// [statusText insertText:str]; // use insertText since statusText is NSTextView class
NSLog(@"Running... %d\n",i);
// [stateLock lock];
if (stopState==true)
break;
// [stateLock unlock];
}
NSLog(@"End of runloop! at %d\n",i);
[runPtr release];
}

- (id)sender
{
// NSAutoreleasePool *stopPtr = [[NSAutoreleasePool alloc] init];


NSLog(@"Press stop button\n");
// [NSThread detachNewThreadSelector: @selector(stopLoop) toTarget:self withObject:nil];
// [runThread exit];
// [sender setEnabled:NO]; // disable the stop button
// stopState = true;

// [stopPtr release];
}
- (void) stopLoop
{
NSAutoreleasePool *stopPtr = [[NSAutoreleasePool alloc] init];
NSLog(@"In stopLoop\n");
// [stateLock lock];
while(!stopState){


if ([stopBut state] == NSOnState){NSLog(@"In side loop stopLoop\n");
stopState = true;}
}
// [stateLock unlock];
// [self performSelectorOnMainThread:@selector(hasStopped) withObject:NULL waitUntilDone:false];
[stopPtr release];
}
@end
 _______________________________________________
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

  • Follow-Ups:
    • Re: How can I stop running loop?
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: Mac OS 10.3 Help - hyperlinks do not work
  • Next by Date: Re: Do something before creating a new file
  • Previous by thread: Re: Mac OS 10.3 Help - hyperlinks do not work
  • Next by thread: Re: How can I stop running loop?
  • Index(es):
    • Date
    • Thread