Re: Techniques for thread communication
Re: Techniques for thread communication
- Subject: Re: Techniques for thread communication
- From: Tito Ciuro <email@hidden>
- Date: Sun, 7 Sep 2003 23:37:02 +0200
Eric,
I'd choose another method, found in NSThread.h:
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
waitUntilDone:(BOOL)wait modes:(NSArray *)array;
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
waitUntilDone:(BOOL)wait;
The only problem is that these two methods are found in 10.2 and
onwards. If you want another option, I suggest looking at this post:
http://cocoa.mamasam.com/MACOSXDEV/2001/06/2/8592.php
I hope this helps,
-- Tito
On domingo, sept 7, 2003, at 23:21 Europe/Paris, Eric Scharff wrote:
>
I have a thread that continuously does computationally expensive
>
things in the background, but which occasionally needs to
>
present information to the user. Since the AppKit is mostly
>
not-reentrant, I want to make sure I do this the "right way."
>
>
It seems I have several options:
>
>
1. Use the NSNotificationCenter. The thread posts messages when
>
data is available, and the main app gets these events and
>
updates.
>
>
2. Use NSConnection to establish a communication channel between
>
the "main app" and the thread, and send messages through the
>
distributed object proxies.
>
>
3. Use an NSTimer in the main app to periodically poll the
>
thread.
>
>
4. Use NSInvocation somehow for the thread to push messages to
>
the main app.
>
>
I'm leaning heavily toward (1) because the code is the simplest
>
and cleanest. Option (2) is somewhat appealing because
>
eventually I could replace the local server with a cluster of
>
distributed servers.
>
>
Will these four approaches all work? Are there better ways?
>
What is the trade-off between these different techniques? Most
>
importantly, is there a big performance hit for using the
>
NSNotificationCenter?
>
>
Thanks,
>
>
-Eric
>
>
>
__________________________________
>
Do you Yahoo!?
>
Yahoo! SiteBuilder - Free, easy-to-use web site design software
>
http://sitebuilder.yahoo.com
>
_______________________________________________
>
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.
_______________________________________________
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.