Skip to content

stonly916/SafeThreadDispatchSemaphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

SafeThreadDispatchSemaphore(STONLYThreadSemaphore)

use dispatch_semaphore_t for thread safety

code


  #define ST_SEMAPHORE_LOCK(semString,...) \
  [[STONLYThreadSemaphore shareInstance] semaphoreLock:semString];\
  __VA_ARGS__;\
  [[STONLYThreadSemaphore shareInstance] semaphoreUNLock:semString];

how to use

just use: ST_SEMAPHORE_LOCK(semString, ... )
different lock use different semString


dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
        ST_SEMAPHORE_LOCK(@"homeTest",NSLog(@"lock-homeTest1"));
    });

About

use dispatch_semaphore_t for thread safety //线程安全

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published