[newbie:] elegant way using multithreading with NSThreads
[newbie:] elegant way using multithreading with NSThreads
- Subject: [newbie:] elegant way using multithreading with NSThreads
- From: Wolfgang Maehr <email@hidden>
- Date: Sun, 13 Mar 2005 05:12:59 +0100
Hi all,
I'm sorry if I ask a question with an simple answer, but as I'm pretty
new to ObjC and never uses multithreading in object orientation, I went
through the Apple documentation and some of the examples, but I didn't
really find an answer to my question. (I don't know if it's just me,
but I find the Apple doc too basic, too little advanced examples and
advances descriptions).
I want my (command-line) App having multiple threads:
Main thread shall be a controller thread waiting for commands and
forwarding these to the appropriate objects to set options, start and
stop, and so on. Like a controller for a kernel. This controller object
(in thread 1) has a tracker object (that tracks the mouse location),
which shall be doing the tracking in a separate thread to get enough
performance. This splitting I can do with the [NSThread
detachNewThreadSelector:...] method, which lets thread loop in now in a
tracking loop. This loop also checks from time to time, if there are
new steering commands (in my message queue) to process and processes
these when needed. So far everything is pretty straight-forward, the
way I would do it in functional multithreading with pthreads...
The problem is that this thing crashes and I somehow have the feeling,
as the Apple doc speaks about the NSProxy to do inter-thread,
inter-application and inter-machine communication. But in this context
I don't see the sense of using them, as the objects are any-ways known.
The controller holds the tracker and calls methods of it.
Synchronisation is made via a NSConditionLock...
1) The NSProxy: Do I NEED to use it? I can get it via the [NSConnection
rootProxyForConnectionWithRegisteredName:...] method, but as said
before this seems to be useless for me. Only, if this proxy contains a
Message-Queue, so that I don't have to implement it, but as I haven't
found any notification method, I wonder a bit, if it brings something.
2) I use mutex' in the tracker, where members may be accessed from
different threads. Do I also need a mutex when accessing the whole
tracker object, which runs in parallel in the other thread?
3.) Is there a elegant way of directly "an object in another thread". I
put it under quotes, as objects AFAIK are not in different threads, but
I'd be glad if I could just write a method, that creates this object,
where all methods are automatically run in the other thread and
accessed via a NSProxy?
4.) Is there good literature (except the Apple papers) about this
object-oriented multithreading and "kernel-client-architecture", may
also be for another similar language?
Thanks in advance, I'm glad for any help,
_Wolf
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden