title: GCD and RunLoops
body: <p>In my app I add an <em>CFMachPortRef</em> (via <em>CFMachPortCreateRunLoopSource</em>) to a threads <strong>CFRunLoop</strong></p>
  
  <p>Now i was asking myself, can this be done using GCD? Let's say instead of spawning my own <em>NSThread</em> and add the created <em>CFRunLoopSourceRef</em> to its run loop via <em>CFRunLoopAddSource</em>, add the event port to a dispatch's runloop?</p>
  
  <p>I think this will most likely not work due to the inner workings of GCD, but I really don't know.</p>
  
  <p><strong>Update</strong></p>
  
  <hr>
  
  <p>I got this so far, however neither the callback function for the event tap nor the dispatch_source_event_handler block is called. Any ideas?</p>
  
  <pre><code>CFMachPortRef port = CGEventTapCreate(kCGSessionEventTap,
                                        kCGHeadInsertEventTap,
                                        opts,
                                        desc_.eventMask,
                                        _CGEventCallback,
                                        self);
  
  // create dispatch source
  dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV,
                                                    CFMachPortGetPort(port),
                                                    0,
                                                    dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
  
  // set event handler
  dispatch_source_set_event_handler(source, ^{
      printf("handle me!\n");
  });
  
  dispatch_resume(source);
  </code></pre>