Re: interthread communication
Re: interthread communication
- Subject: Re: interthread communication
- From: Andreas Wolf <email@hidden>
- Date: Fri, 13 Jul 2001 16:52:47 -0700
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?
tia,
dan
I've tried Distributed Objects, NSPorts and their messsages,
NSDistributedNotifications and I think a couple more..
but the only thing that really worked for me, when sending frequent
(about 50 per second) messages between
a working thread and a UI thread was using basic C types (C-strings,
integers,..) and
NSLock's, i.e. whenever you access any shared value you lock them, to
prevent the other thread from
accessing that same value at the same time.
NSStrings and others didn't seem to be thread save although the cocoa
release notes
says so. Distributed Objects, NSPortMessages were too slow and
everything else I've tried
(even sample code posted on this list and other lists to date) didn't
work for me either.
I am surprised that your solution with notifications to the
defaultCenter works. When I tried
this the thread that sent the notification was also the receiving thread
(no inter-thread communication).
However, like John said, if it works its fine... why change it? :)
-A