Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //other necessary includes
- #include <stdlib.h>
- #include <stdio.h>
- #include <dispatch/dispatch.h>
- typedef void (^voidBlock)(void);
- typedef int (^intBlock)(int);
- void doAsyncWork(voidBlock theWork) {
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_async(queue, block);
- }
- int main(int argc, char** argv) {
- dispatch_semaphore_t workDone = dispatch_semaphore_create(0);
- doAsyncWork( ^ {
- //something expensive
- dispatch_semaphore_signal(workDone);
- });
- dispatch_semaphore_wait(workDone);
- dispatch_release(workDone);
- printf("yay work finished!\n");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement