Created
November 16, 2017 08:22
-
-
Save wuchuwuyou/c581037660f0439ce5981e93d4076f3d to your computer and use it in GitHub Desktop.
runloop 阻塞线程
This file contains 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
@implementation ViewController{ | |
BOOL end; | |
} | |
– (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSLog(@”start new thread …”); | |
[NSThread detachNewThreadSelector:@selector(runOnNewThread) toTarget:self withObject:nil]; | |
while (!end) { | |
NSLog(@”runloop…”); | |
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; | |
NSLog(@”runloop end.”); | |
} | |
NSLog(@”ok.”); | |
} | |
(void)runOnNewThread{ | |
NSLog(@”run for new thread …”); | |
sleep(1); | |
[self performSelectorOnMainThread:@selector(setEnd) withObject:nil waitUntilDone:NO]; | |
NSLog(@”end.”); | |
} | |
-(void)setEnd{ | |
end=YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment