1、
dispatch_queue_t queue = dispatch_queue_create(“test”, DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
sleep(500);
NSLog(@“1”)
});
dispatch_sync(queue, ^{
sleep(300);
NSLog(@“2”);
});
sleep(100)
NSLog(@“3”);
注:补充下,当时对方说了个前提,这个是在主线程里
2、
int a = 1;
int main() {
int b = 2;
static int c = 3
Block block = ^ {
a = 10;
b = 20;
c = 30;
};
a = 100;
b = 200;
c = 300;
block();
NSLog(@“a:%ld”, a);
NSLog(@“b:%ld”, b);
NSLog(@“c:%ld”, c);
}