Re: interthread communication
Re: interthread communication
- Subject: Re: interthread communication
- From: email@hidden
- Date: Sat, 14 Jul 2001 21:13:51 +0200
Le samedi 14 juillet 2001, ` 01:18, John C. Randolph a icrit :
On Friday, July 13, 2001, at 02:46 PM, Dan Watson wrote:
what is the recommended way of communicating between threads? I'm
writing an
internet client application, and I have all the protocol and networking
stuff in one thread. how can I safely send messages to a controller for
instance to update the UI?
right now, I'm just posting notifications to the app's defaultCenter and
letting the controller catch them and perform operations on the UI. is
this
acceptable?
If it works, it's acceptable ;-)
-jcr
[Objc retain];
No, it is not, and it really doesn't work.
The notification center does not belong to a particular thread. That means
that if you post a notification to the default center, it is sended
immediatly (in the SAME thread) to the receivers. Except if it happens
that the system switched thread in the middle of the notification post,
you are not doing multithreaded communication. You could get huge problems
(crashes) if you put the system in an inconsistent state due to the fact
that you are doing something in the wrong thread.
Try to put lines like
NSLog(@"here it is %@", [NSThread currentThread]);
to know which is the current thread executing your notifications.
For interthread communication, you have to use DO (= Distributed Objects).
Thomas Lachand-Robert
********************** email@hidden
The Commandant Project:
http://lachand.free.fr/
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.