|
From: Ethan M. <merritt@u.washington.edu> - 2007-03-30 21:50:29
|
On Friday 30 March 2007 10:41, Timoth=C3=A9e Lecomte wrote: >=20 > - I tried on the sample app what is the second most important aspect of > the wxt implementation: putting the event loop in a separate thread. And > bingo ! I get the same problem as with wxt... Although the separate thread > and its event loop are running, the latter does not process the window > events. It turns out that this is a limitation of Cocoa app (MacOS > programming toolkit): > "The main thread of the application is responsible for handling events. > The main thread is the one blocked in the run method of NSApplication, > usually invoked in an application=C2=92s main function. " > (http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading= /articles/CocoaSafety.html) Hmm. I'm not sure I read that document the same way you do. It says: Events The main thread of the application is responsible for handling events. The main thread is the one blocked in the run method of NSApplication, usually invoked in an application=E2=80=99s main function. While the Applic= ation Kit continues to work if other threads are involved in the event path, operations can occur out of sequence. For example, if two different threads are responding to key events, the keys could be received out of ord= er. By letting the main thread process events, you achieve a more consistent us= er experience. Once received, events can be dispatched to secondary threads for further processing if desired. You can call the postEvent:atStart: method of NSApplication from a secondary thread to post an event to the main thread= =E2=80=99s event queue. Order is not guaranteed with respect to user input events, how= ever. The main thread of the application is still responsible for handling events in the event queue. Note the phrase: "if two different threads are responding to key events, the keys could be received out of order". To me that implies that it is indeed possible to do event handling in the daughter threads. It is just warning you that the sequence of handling is not guaranteed, which is not surprising. > I've searched for this "run" method in the wxWidgets code, but could not > find it. MacOS development involves a mixture of layers called Foundation, > Cocoa and Carbon (like GLib, Cairo, GTK and friends) and I'm afraid this > 'run' method is in fact hidden somewhere else. Perhaps section 4.2.2 of this document is useful? developer.imendio.com/files/ developer/Porting-Gtk-MacOSX.pdf=20 =2D-=20 Ethan A Merritt Courier Deliveries: 1959 NE Pacific Dept of Biochemistry Health Sciences Building University of Washington - Seattle WA 98195-7742 |