-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.m
More file actions
68 lines (45 loc) · 1.17 KB
/
main.m
File metadata and controls
68 lines (45 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#import <Foundation/Foundation.h>
void testQueueSuspensionFromSelf()
{
NSLog(@"== suspend from self ==");
dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
NSLog(@"suspending");
dispatch_suspend(queue);
});
dispatch_async(queue, ^{
NSLog(@"should have suspended");
});
sleep(5);
}
void testExternalQueueSuspensionWaitsForPendingBlocks()
{
NSLog(@"== suspend externally ==");
dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_SERIAL);
__block BOOL cont = NO;
dispatch_async(queue, ^{
volatile BOOL *pc = &cont;
NSLog(@"started");
while (!(*pc)) {
sleep(1);
}
NSLog(@"exiting");
});
// Allow it to start
sleep(1);
dispatch_async(queue, ^{
NSLog(@"second block");
});
// Suspend the queue
NSLog(@"suspending");
dispatch_suspend(queue);
// Allow it to continue. If dispatch_suspend waits, the app should be hung.
// If it does not, "exiting" will be printed.
cont = YES;
sleep(5);
}
void main(void)
{
testQueueSuspensionFromSelf();
testExternalQueueSuspensionWaitsForPendingBlocks();
}