Re: Communication between Cocoa and Carbon threads
Re: Communication between Cocoa and Carbon threads
- Subject: Re: Communication between Cocoa and Carbon threads
- From: Jens Alfke <email@hidden>
- Date: Wed, 5 May 2010 11:34:44 -0700
On May 4, 2010, at 10:30 PM, Abhijeet Singh wrote:
> I have read in Mac OSX Technology overview that we can integrate Carbon with Cocoa application. So can anybody suggest what are the possible ways to send message from Cocoa thread to Carbon thread in an Cocoa Application.
There’s really only one kind of thread in an app, although there are multiple APIs (NSThread, pthreads, Carbon’s MP calls). So the question is how to message between threads in general.
If your Carbon code uses runloops already, you can use Mach ports and messages for communication, using CoreFoundation APIs. (I am pretty sure there is Apple sample code demonstrating how to do this.)
If not, you may have to roll your own techniques using classic techniques like a thread-safe queue. Implement the queue with a C or C++ API, and then you can use it from both Carbon and Cocoa code. One thread can then push messages into the queue while another thread runs a loop that pulls messages as they arrive.
—Jens_______________________________________________
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