Search code examples
objective-cmacoscocoamacos-carbon

What is the Cocoa or Carbon replacement equivalents of deprecated Multiprocessing Services on OSX?


So I'm working on updating a large project from really old C++/Carbon code, and I keep running into deprecated functions.

So I guess there are 2 aspects to this question.

The immediate question is:

What should be used instead of the following functions which were deprecated in 10.7? Are there Cocoa equivalents, or updated Carbon equivalents?

MPCreateEvent MPDeleteEvent MPWaitForEvent MPSetEvent

And the second part of the question is, is there some place on the Apple developer site - or elsewhere - that I can find more information about what should be used in cases where old code is officially deprecated?


Solution

  • First off, you should read the Concurrency Programming Guide. There are several ways to achieve concurrency in Cocoa apps and that guide explains them all in detail.

    Probably the closest analogue to the Carbon functions are the various Grand Central Dispath (GCD) functions, which allow you to run code in a background process by passing an Objective-C block:

    dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(aQueue, ^{
        NSLog(@"Do some work in the background here.");
    });
    

    This is all explained in detail in the concurrency docs. Unfortunately, I was unable to find any documentation about the deprecation of the Multiprocessing API. However, that API is very old, dating back to before Mac OS X, and I suspect Apple are assuming that most of the code using it is long-dead. I don't envy you your task!

    Note that GCD and blocks were introduced in 10.6. If for some reason you need to support 10.5, you can use the NSOperation methods which were introduced in that version of the OS. These are not as easy to use as GCD but they can achieve a similar result. NSOperation is still available and very good for certain use cases.