Last active
March 8, 2019 08:23
-
-
Save chance395/ed0f61fd4d765ab6e365404b91f8df43 to your computer and use it in GitHub Desktop.
#ios->多线程
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@property (nonatomic, strong) void (^dispath_queueNoParaCompletion)(void); | |
@property (nonatomic, strong) void (^dispath_queueCompletion)(dispatch_semaphore_t semaphore); | |
+(void)callSemaphoreSyncQueueUseConcurrentStr:(char*)constChar WithCompletionBlock:(void(^)(dispatch_semaphore_t semaphore))completionBlock | |
{ | |
if (completionBlock) { | |
self.dispath_queueCompletion = completionBlock; | |
} | |
dispatch_queue_t queue = dispatch_queue_create(constChar, DISPATCH_QUEUE_CONCURRENT); | |
dispatch_async(queue, ^{ | |
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | |
!self.dispath_queueCompletion ? :self.dispath_queueCompletion(semaphore); | |
}); | |
} | |
[JJDispatch_queue callSemaphoreSyncQueueUseConcurrentStr:"example" WithCompletionBlock:^(dispatch_semaphore_t _Nonnull semaphore) { | |
[self actionA:^{ | |
dispatch_semaphore_signal(semaphore); | |
NSLog(@"A-------->>>>>"); | |
}]; | |
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | |
[self actionB:^{ | |
sleep(3); | |
dispatch_semaphore_signal(semaphore); | |
NSLog(@"B-------->>>>>"); | |
}]; | |
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | |
[self actionC:^{ | |
NSLog(@"C-------->>>>>"); | |
}]; | |
}]; | |
-(void)actionA:(void(^)(void))completionBlock | |
{ | |
if (completionBlock) { | |
_NoParaCompletion=completionBlock; | |
_NoParaCompletion(); | |
} | |
} | |
-(void)actionB:(void(^)(void))completionBlock | |
{ | |
if (completionBlock) { | |
_NoParaCompletion =completionBlock; | |
_NoParaCompletion(); | |
} | |
} | |
-(void)actionC:(void(^)(void))completionBlock | |
{ | |
if (completionBlock) { | |
_NoParaCompletion =completionBlock; | |
_NoParaCompletion(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment