]> git.saurik.com Git - apple/libdispatch.git/blob - testing/dispatch_deadname.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / dispatch_deadname.c
1 #include <dispatch/dispatch.h>
2 #include <mach/mach.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <assert.h>
7
8 #include "dispatch_test.h"
9
10 int
11 main(void)
12 {
13 test_start("Dispatch dead-name notification");
14
15 dispatch_async(dispatch_get_concurrent_queue(0), ^{
16 mach_port_t mp = pthread_mach_thread_np(pthread_self());
17 dispatch_source_t ds0;
18 kern_return_t kr;
19
20 assert(mp);
21
22 kr = mach_port_mod_refs(mach_task_self(), mp, MACH_PORT_RIGHT_SEND, 1);
23
24 assert(kr == 0);
25
26 ds0 = dispatch_source_machport_create(mp, DISPATCH_MACHPORT_DEAD, NULL, dispatch_get_main_queue(),
27 ^(dispatch_event_t de) {
28 dispatch_release(dispatch_event_get_source(de));
29 test_stop();
30 exit(EXIT_SUCCESS);
31 });
32
33 test_ptr_notnull("dispatch_source_machport_create", ds0);
34
35 // give the mgr queue time to start, otherwise the mgr queue will run
36 // on this thread, thus defeating the test which assumes that this
37 // thread will die.
38 sleep(1);
39 });
40
41 dispatch_main();
42
43 return 0;
44 }