• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMessagePort crashes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMessagePort crashes


  • Subject: Re: NSMessagePort crashes
  • From: Stephan Lichtenauer <email@hidden>
  • Date: Sun, 23 Jan 2005 20:34:12 +0100

Hi Gwynne,

thanks a lot for the example, especially your explanations! With them I got it working within 3 minutes...

Am 23.01.2005 um 19:30 schrieb Gwynne:

On Jan 23, 2005, at 11:15 AM, Stephan Lichtenauer wrote:
I have written a small test program to use NSMessagePorts/NSPortMessages but at best the message is not received and in the worst case the program crashes with a EXC_BAD_ACCESS.

Below is my code, when I initialize the message as it can be seen with the distantPort, the app crashes, when I init. it with a send port of nil it does not crash but the message is not received nevertheless (push is attached to a button in the IB)... I looked everywhere on the net and in my "Core Mac OS X and Unix Programming" and Cocoa books and could not find much example code that would help, all the code I found looked more or less what I did...

I suggest taking a look at the ThreadMessage code by Dustin Mierau, which can be found at <http://www.blackholemedia.com/code/>. A quick summary of what his code does differently than yours:


- Use [[NSPort port] retain] instead of NSMessagePort. NSPort creates an NSMachPort by default, which will work better for OS X-local messaging. I'm not sure if NSMessagePort by itself works at all.


That was it, thanks. I took the NSMessagePort code from the newest Apple multithreading document here, so I never thought that might be the problem: http://developer.apple.com/documentation/Cocoa/Conceptual/ Multithreading/index.html
I think I will post a bug report...


- Use [localPort scheduleInRunLoop:forMode:] I know the headers say not to do that, but he does it and it works.

- Use localPort as the send port and don't use any receive port. It's a one-way message; the receive port is for replies.

- Don't use nil for the components. Send something, even if you just put [NSArray arrayWithObject:[NSNull null]].

Using nil and the documented addPort: instead of scheduleInRunLoop: was no problem.


[zipped many more interesting and helpful explanations, which though were not the reason for the crash]

Thanks again and best regards

Stephan

_______________________________________________
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


References: 
 >NSMessagePort crashes (From: Stephan Lichtenauer <email@hidden>)
 >Re: NSMessagePort crashes (From: Gwynne <email@hidden>)

  • Prev by Date: Re: index column in bound NSTableView
  • Next by Date: why is nsscanner giving me an extra result?
  • Previous by thread: Re: NSMessagePort crashes
  • Next by thread: Application without menu: How to get Cmd-C event?
  • Index(es):
    • Date
    • Thread