Re: threads in Xcode
Re: threads in Xcode
- Subject: Re: threads in Xcode
- From: Chris Hanson <email@hidden>
- Date: Thu, 22 Jul 2004 16:14:51 -0700
On Jul 22, 2004, at 2:20 PM, Mai Bui wrote:
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.
An outlet is just an instance variable that points to an object that
was (potentially) wired up in Interface Builder. What type of object
does your statusText object refer to?
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.
The method John was referring to is -[NSObject
performSelectorOnMainThread:withObject:waitUntilDone:].
===> 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?
First of all, each invocation of +[NSThread
detachNewThreadSelector:toTarget:withObject:] creates a new thread. So
your run button action and your stop button action are creating
independent threads, not the same thread.
Secondly, since your stopState instance variable is manipulated by two
threads, you need to synchronize access to it via a lock or some other
synchronization primitive (such as @synchronized).
Finally, in your run button action it looks like you're assuming the
new thread will pause execution of the action until the thread
completes. That's not the case; the thread is preemptive and
completely independent from the main thread.
-- Chris
_______________________________________________
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.