-(void) Touchesbegan: (nsset<uitouch *> *) touches withevent: (uievent *) event
{
//Home row Async
[Self mainqueueasync];
//Home row synchronization
[Self mainqueuesync];
// resolution of deadlocks
[Self demo];
}
// resolution of deadlocks
-(void) demo
{
NSLog(@ "Begin");
// asynchronous
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//Home column The home column performs the task only when the main thread is idle
dispatch_queue_t mainqueue = dispatch_get_main_queue();
//2. Task
dispatch_block_t Task1 = ^ {
[nsthread sleepfortimeinterval: 1.0];
NSLog(@ "Task1%@", [nsthread currentthread]);
};
dispatch_block_t Task2 = ^ {
NSLog(@ "Task2%@", [nsthread currentthread]);
};
// sync
Dispatch_sync(Mainqueue, Task1);
Dispatch_sync(Mainqueue, task2);
});
NSLog(@ "End");
}
Home row Sync deadlock
-(void) Mainqueuesync
{
NSLog(@ "Begin");
//Home column The home column performs the task only when the main thread is idle
dispatch_queue_t mainqueue = dispatch_get_main_queue();
//2. Task
dispatch_block_t Task1 = ^ {
[nsthread sleepfortimeinterval: 1.0];
NSLog(@ "Task1%@", [nsthread currentthread]);
};
dispatch_block_t Task2 = ^ {
NSLog(@ "Task2%@", [nsthread currentthread]);
};
// sync
Dispatch_sync(Mainqueue, Task1);
Dispatch_sync(Mainqueue, task2);
NSLog(@ "End");
}
The task for the Home row asynchronous home column is performed only in the main thread, in turn
-(void) Mainqueueasync
{
//Home row
dispatch_queue_t mainqueue = dispatch_get_main_queue();
//2. Task
dispatch_block_t Task1 = ^ {
[nsthread sleepfortimeinterval: 1.0];
NSLog(@ "Task1%@", [nsthread currentthread]);
};
dispatch_block_t Task2 = ^ {
NSLog(@ "Task2%@", [nsthread currentthread]);
};
// asynchronous
Dispatch_async(Mainqueue, Task1);
Dispatch_async(Mainqueue, task2);
}
Troubleshooting Deadlocks in multiple threads