2 * Copyright (c) 2009 Mark Heily <mark@heily.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <sys/event.h>
23 #include <dispatch/dispatch.h>
25 pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
28 void test_countdown(void);
38 final_countdown(void *arg, size_t count)
40 static int europe = 10;
43 printf("It's the final countdown..\n");
46 printf("%d.. ", europe);
50 pthread_mutex_lock(&mtx);
52 pthread_mutex_unlock(&mtx);
56 http://developer.apple.com/mac/articles/cocoa/introblocksgcd.html
61 dispatch_source_t timer;
64 timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
65 dispatch_get_current_queue()); //NOTE: q_default doesn't work
66 now = dispatch_walltime(DISPATCH_TIME_NOW, 0);
67 dispatch_source_set_timer(timer, now, 1, 1);
68 dispatch_source_set_event_handler_f(timer, say_hello);
69 puts("starting timer\n");
76 dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),
77 NULL, final_countdown);
82 main(int argc, char **argv)
86 if (strcmp(argv[0], "--no-proc") == 0)
97 "+OK All %d tests completed.\n", testnum - 1);