NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; initData(); __block int sum = 0; // Create a semaphore with 0 resource __block dispatch_semaphore_t sem = dispatch_semaphore_create(0); __blockdispatch_semaphore_t taskSem =dispatch_semaphore_create(0); // create dispatch semaphore dispatch_queue_t queue = dispatch_queue_create("StudyBlocks",NULL); dispatch_block_t task1 = ^(void) { int s = 0; for (int i = 0; i < Length; i++) s += data; sum = s; NSLog(@" >> after add: %d", sum); dispatch_semaphore_signal(taskSem); };