views:

7

answers:

0

I have created a worker thread that uses a CFRunLoop to receive messages from a CFSocket.

Now I need to send other messages to the worker thread so a CFMessagePort looked ideal. However its entirely non obvious to use: The documentation states that the name parameter is needed when communicating between processes.

In my worker thread I have this code:

CFRunLoopPortRef port = CFMessagePortCreateLocal(kCFAllocatorDefault,NULL,MessageProc,&ctx,&f);
CFRunLoopSourceRef = CFMessageMortCreateRunLoopSource(kCFAllocaorDefault,port,0);
CFRunLoopAddSource(_runLoop,source,kCFRunLoopCommonModes);
CFRelease(source);

In the main thread, when I try to send a message using CFMessagePortSendRequest I get a EXC_BAD_ACCESS somewhere internally.

I am beginning to suspect that the 'local' and 'remote' sides of a message port might not just be for inter-process usage, and CFMessagePortSendRequest expects a CFMessagePortCreateRemote port - in which case I can't share the local message port instance between threads.

If I have to use CFMessagePortCreateRemote I can't see how to elegantly avoid name conflicts between different instances of my app.