Re: Inter-thread communications (live/deadlock?)
Re: Inter-thread communications (live/deadlock?)
- Subject: Re: Inter-thread communications (live/deadlock?)
- From: Keary Suska <email@hidden>
- Date: Wed, 16 Jul 2008 10:05:46 -0600
- Thread-topic: Inter-thread communications (live/deadlock?)
7/15/08 3:45 PM, also sprach email@hidden:
> I have a problem with inter-thread communications with NSMachPort/
> NSPortMessage - it works one way after initially working both ways..
First off, post your code. We can't say what you are doing wrong if we can't
see what you have done wrong.
> The application has a main parent thread that spawns a child thread.
> The child thread runs inside an object instance.
>
> The parent passes it's NSMachPort instance through the NSThread
> detachNewSelector to the child. The parent runs a loop and drives
> it's RunLoop.
Is the "parent" a spawned thread as well, i.e. not the "main" thread?
> The child once spawned creates it's own NSMachPort instance and then
> packages it up and sends it to the parent (which the parent receives
> correctly). This is the classic Apple documented 'checkin'. It then
> enters the classic while(1) { RunLoop ... } to drive the runloop.
Do you attach the mach port to the run loop? If you don't, the loop will
just exit and not process any events. This would explain the behavior you
are seeing, if it is the case.
> Assumption #1 - as the threads are both running "currentRunLoop" then
> I'm assuming that each thread has it's own RunLoop instance? I
> understand that the RunLoop is thread unsafe.
Yes, each thread will have it's own runloop object. Yes, Runloops are not
thread safe.
> The parent can issue as many messages as it likes to the child
> process. Each message gets to the child thread without a problem -
> each and every time.
>
> Now comes the interesting bit. The child uses a single method for all it's
> send calls back to the parent thread - even the checkin uses it - where it
> calls [NSPortMessage sendMessage: ...]. The observed results are that the
> initial checkin message gets to the parent handlePortMessage: whereas
> subsequent calls don't show any errors but the message does not arrive at
> handlePortMessage on the parent. They just vanish. The child and parent
> threads continue as if nothing has happened. The parent can still issue
> messages to the child..
You may also--if you don't already--watch for
NSPortDidBecomeInvalidNotification notifications on both threads. See
NSNotificationCenter class & related docs for more info, if you aren't
familiar.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden