IOS multi-core processing code

Source: Internet
Author: User
// 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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.