// Multi-core accelerated processing function // during the blocking period, a thread with the same number of processor cores is created to execute the callback function // For example, a dual-core will execute the following method // pfun (0, 2) // pfun (1, 2) inlinevoid multicoreprocessing (void (^ pfun) (INT I _thread, int num_thread) {nsuinteger processorcount = [[nsprocessinfo processinfo] processorcount]; // execute if (! Opt_multicore | processorcount = 1) {pfun (0, 1); return;} unsigned short int COUNT = processorcount; // semaphore dispatch_semaphore_t * sempart = (dispatch_semaphore_t *) malloc (sizeof (dispatch_semaphore_t) * count); // start for (INT I = 0; I <count; I ++) {// create a waiting semaphore sempart [I] = dispatch_semaphore_create (0); dispatch_async (dispatch_get_global_queue (dispatch_queue_priority_high, 0), ^ (void) {// execute the callback method pfun (I, count); dispatch_semaphore_signal (sempart [I]) ;}// wait until the task ends for (INT I = 0; I <count; I ++) {dispatch_semaphore_wait (sempart [I], dispatch_time_forever); dispatch_release (sempart [I]);} Free (sempart);} usage: void (^ pfun) (INT, INT) = ^ void (INT I _thread, int num_thread) {// splits the image data into num_thread for execution, each thread processes part of the data tibitmapdata * bitmappart = splitbitmap (bitmap, I _thread, num_thread); adjustvibrance (* bitmappart, saturation, Vibrance); Delete bitmappart;}; multicoreprocessing (pfun );