Re: Follow-up: Cocoa thread-safety
Re: Follow-up: Cocoa thread-safety
- Subject: Re: Follow-up: Cocoa thread-safety
- From: Steve Klingsporn <email@hidden>
- Date: Sat, 26 Oct 2002 11:00:11 -0500
If I keep a reference to the main NSRunLoop, and call
performSelectorWithOrder()
from the main thread, everything works fine. If I call
performSelectorWithOrder()
from any other thread, the selector simply is not performed. For the
"modes"
parameter, I've tried manually setting them, and calling
NSRunLoop.allModes()
to get the NSArray of modes. No luck.
Multithreading can be hard to debug, but the world is essentiall
multithreaded.
Lots of things going on at once, and lots of things going on which
observe or
interact with these processes. Multithreaded is definitely the way to
go...
Otherwise, you end up with issues like dragging a window around and
watching everything else get choppy -- which happens a great deal on OS
X,
and is quite a shame.
For a fun exercise, copy and paste 3000 lines from two different source
files in
ProjectBuilder to Mail.app, address it, and send it to a friend or
yourself while you
are listening to a song in iTunes. =) Ouch.
Steve
On Saturday, October 26, 2002, at 12:39 AM, Nicholas Riley wrote:
On Fri, Oct 25, 2002 at 11:07:03PM -0500, Steve Klingsporn wrote:
Unfortunately, NSThread is not available from Java, nor do these
methods seem to be relocated as the Java counterparts often are. I
suppose it might be possible to write some code that uses JNI or the
Java Bridge to do this, but this violates my desire to keep everything
Java. My timer approach works, but using 4% of the CPU to run a timer
4 times a second seems a bit extreme to me.
What about NSRunLoop?
public void performSelectorWithOrder( NSSelector aSelector, Object
target, Object anArgument, int order, NSArray modes)
I've never done any Cocoa-Java, but that looks like something you
could use to do what you want.
To offer a counterpoint, I am _so_ glad that Apple doesn't consider
threads the solution to everything. The runloop stuff handles about
90% of what you'd use threads for, and in a very elegant fashion for
typical event-driven apps IMO. Multithreading, especially in
languages with no memory protection, can be the cause of very
hard-to-debug problems.
--
=Nicholas Riley <email@hidden> |
<http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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.