• 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: John Timmer <email@hidden>
  • Date: Tue, 20 Jul 2004 08:18:46 -0400

Mai -

I missed your earlier mail to the list, so I can't answer all your
questions, but a few things stand out:


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

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.

A second is, why have the start and stop buttons call the same method?
> [NSThread detachNewThreadSelector: @selector(runLoop:) toTarget:self
> withObject:nil];
The method itself doesn't distinguish who's calling it, so you're just going
to be running two threads doing the same thing.

The following is fine (or at least something similar has worked for me),
other than that it's not clear if you have to declared the BOOL in between
the brackets in the header file - that's where it needs to be done.

> For example:
> ...
> BOOL stopState;
> (in the initial:
> ...
> stopState = false;
> ...)
> ...
> (and the runLoop())
> - (void) runLoop:(id)object
> {
> int i;
> NSAutoreleasePool *runPtr = [[NSAutoreleasePool alloc] init];
> NSString *str = @"print out the string\n";
> for (i=0; i<1500; i++)
> {
> [statusText insertText:str]; // use insertText since statusText is
> NSTextView class
> NSLog(@"Running... %d\n",i);
> if (stopState)
> break;
> }
> NSLog(@"End of runloop!%d\n",i);
> [runPtr release];
> }
>
> (and the stopButton() )
> - (IBAction)stopButton:(id)sender
> {.....
> stopState = true;
> .....

_______________________________________________
This mind intentionally left blank
_______________________________________________
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: Mai Bui <email@hidden>
References: 
 >Re: threads in Xcode (From: Mai Bui <email@hidden>)

  • Prev by Date: Would bindings make sense ?
  • Next by Date: Re: Open Recent menu
  • Previous by thread: Re: threads in Xcode
  • Next by thread: Re: threads in Xcode
  • Index(es):
    • Date
    • Thread