gtk2 (gtk1) PostMessage called from thread might not work!
Original Reporter info from Mantis: skalogryyz
-
Reporter name: Dmitry Boyarintsev
Original Reporter info from Mantis: skalogryyz
- Reporter name: Dmitry Boyarintsev
Description:
The attached project shows PostMessage not to work properly if called not from main thread, and if gtk2 (gtk1) window does not getting any standard events.
How to test. Unpack and compile.
Press Button1 (as you can see in the code, the button launches a thread, that will post up to 5 messages to the main project window with 3 sec period).
If window recieves LM_USER message, than it will print msg params and time when msg has been recieved.
Under Linux gtk project. if you press the button, and remove the mouse away from Form. The posted messages will not arrive, until some events happen to form (mouse is back on form, or form has to be redrawn, or TIMER event arrives).
You can test, by pressing the button. And remove mouse from form for 15 sec. Then move mouse back to the form and you'll get all 5 messages in one time.
Under Win32 and Carbon the test works correctly.
Additional information:
Such behavior is caused by using 'emulated' message queue for gtk widgetset. (while under Win32 and Carbon system messge queues are used)
All PostedMessages are handled only then some system event happens, that unstalls main loop waiting (gtk_main_interation). After system events are handled, all emulated messages are processed too.
If no system events happens, all emulated messages will be waiting in the queue.
This situation can be solved, if after posting message to emulated queue, a main loop is also unstalled, that can be achived by adding a idle message to the queue, using gtk_idle_add.
This also required gtk2 widgetset to be thread-safe, and init thread safety on create.
The patch is provided.
Mantis conversion info:
- Mantis ID: 12007
- Fixed in version: 0.9.27 (SVN)
- Fixed in revision: 20818 (#06e83337)
- Target version: 0.9.28