• 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: threads in Xcode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: threads in Xcode


  • Subject: Re: threads in Xcode
  • From: Mai Bui <email@hidden>
  • Date: Thu, 22 Jul 2004 14:20:57 -0700

Thanks John.

> The first being, what is "statusText" in this line:
>> [statusText insertText:str]; // use insertText since statusText is
>> NSTextView class
statusText is a outlet name.

> Unless you could guarantee that statusText is thread safe, you could be
> running into a threading problem, so you should address that by using a
> "callSelectorOnMainThread" instead of a direct call.
I can not find this method.

For now, I ignore using statusText to print out the string. Just
concentrate how the user can run app and stop in the middle way.
My code is simple like following:

BOOL stopState; // global var

- (id)init
{
[super init];
stopState = false;
return self;
}

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

[NSThread detachNewThreadSelector: @selector(runLoop) toTarget:self
withObject:nil];
NSLog(@"Press run button...\n");
[sender setEnabled:YES]; // enable the run button
[stopBut setEnabled:NO]; // disable the stop button
}

- (void) runLoop
{
int i;
NSAutoreleasePool *runPtr = [[NSAutoreleasePool alloc] init];
for (i=0; i<5500; i++)
{
NSLog(@"Running... %d\n",i);
if (stopState==true)
break;
}
NSLog(@"End of runloop! at %d\n",i);
[runPtr release];
}
- (IBAction)stopButton:(id)sender
{
NSLog(@"Press stop button\n");
[NSThread detachNewThreadSelector: @selector(stopLoop) toTarget:self
withObject:nil];
}

- (void) stopLoop
{
NSAutoreleasePool *stopPtr = [[NSAutoreleasePool alloc] init];
stopState = true;
[stopPtr release];
}

===> when the user press "run" button, it runs in the loop, display
"Running..." for 5499 time. The users can not stop appl by pressing
"STOP" button.
Did I miss something here?

Thanks you guys.
M.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: threads in Xcode
      • From: Chris Hanson <email@hidden>
References: 
 >Re: threads in Xcode (From: John Timmer <email@hidden>)

  • Prev by Date: Re: UnArchiving Mutable Array problem...
  • Next by Date: Re: forcing a dialog to be the active (front) window
  • Previous by thread: Re: threads in Xcode
  • Next by thread: Re: threads in Xcode
  • Index(es):
    • Date
    • Thread