Re: threads in Xcode
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.