Q regarding threading issues for SWT mode
Anthony Petrov
anthony.petrov at oracle.com
Thu Dec 15 06:16:58 PST 2011
Hi Scott,
I gave it a try, and indeed, just calling NSApplicationLoad() results in
[NSApp isRunning] returning YES, and as such we're all good for SWT to
start its event loop later. So nothing is broken in 7 when comparing
with Apple JDK 6 in this regard.
It's still a mystery to me why this is so, because the spec for
isRunning states it returns YES when the event loop is running, and in
your previous email you've confirmed that calling NSApplicationLoad()
only initializes an instance of NSApplication, but does not start the
event loop. So why is this method returning YES then? (not that I'm
against that - it works just fine for our design, but I'd like to
understand the reason for the return value of YES from Cocoa perspective).
--
best regards,
Anthony
On 12/14/11 20:08, Scott Kovatch wrote:
>
> On Dec 14, 2011, at 5:10 AM, Anthony Petrov wrote:
>
>> The only issue that is still unclear to me is when an app is started on main thread (to use SWT later), but accesses AWT first (like the one mentioned in MACOSX_PORT-720 - it creates an instance of the Font class before doing anything else).
>>
>> In this case we'll create a simple NSApplication instance by means of calling the NSApplicationLoad(), however, since Cocoa SWT hasn't started its event loop (and hasn't even been initialized yet), [NSApp isRunning] will return NO, and hence we'll start an AWT event loop at line 354.
>
> Hmm… This should be okay. Have you tried it yet? I believe when you use NSApplicationLoad() it treats the NSApplication as being in the running state. At least, I hope that's still the case. Otherwise this design falls apart. :-\
>
>> Will SWT be able to take control of the event loop later? Or will it be able to put up with AWT spinning its own event loop? Or will it simply fail to start up?
>
> No, this is a bad thing. SWT needs to have full control over creating its own NSApplication and running the event loop. SWT then becomes the event pump that also dispatches AWT events to AWT windows. That's because it ignores events not targeted to its windows and lets the base NSApplication event dispatcher handle it. If the AWT is allowed to create and run an NSApplicationAWT, it will sit in [NSApplication run] and never get back out. We'll never get back to the main thread so the SWT can create a Display.
>
>> Or do we simply not support such use case? I.e., should we just require apps to initialize SWT first prior to using any of the AWT APIs?
>
> This did work with Apple's JDK 6, so I would expect it to continue to work with 7.
>
> - Scott
More information about the macosx-port-dev
mailing list