Projects
Wiki     Timeline     Browser     Search     New Ticket     Bug Reports

Ticket #38 (accepted enhancement)

Opened 2 years ago

Last modified 13 months ago

Make a public API for draining the main queue

Reported by: smokris@… Owned by: dsteffen@…
Priority: major Milestone: MacOSX
Version: Keywords:
Cc:

Description

Feature request:
Create a public API that allows applications to poll the main queue, so that enqueued items can execute on Thread 0.

Use case example:
I'm developing a command-line application with an optional Cocoa GUI. I would like to modularize the Cocoa GUI, so that the main command-line application does not make any references to Cocoa unless the GUI module is loaded.

So in the main app, I'd like to simply call dispatch_main() instead of using CFRunLoop or NSRunLoop. But that doesn't work — dispatch_main() terminates Thread 0, which Cocoa needs, and instead runs items enqueued to the main queue on a nonzero thread.

I've found that if, instead of calling dispatch_main(), I do this:

while(1)
{
	_dispatch_main_queue_callback_4CF(0);
	usleep(10000);
}

...I can enqueue GUI blocks using dispatch_get_main_queue() and my Cocoa GUI code works as expected. But it's not safe to use this private SPI.

Change History

comment:1 Changed 13 months ago by dsteffen@…

  • Owner set to dsteffen@…
  • Status changed from new to accepted
Note: See TracTickets for help on using tickets.