Hozzászólások
Sziasztok!
Van 1 olyan problémám, hogy 2 szálon fut az aplikációm, az egyikben standard GTKs ablakrendszer (GTK++ban összeütve): néhány nyomógombbal (folyamat irányítása) + DrawingArea, melybe grafikont rajzolok a másik szál által kiszámított adatok alapján timer segítségével,
a baj ott kezdődik, hogy a grafikon aktualizálásakor kaotikusan viselkedik a progi, mintha nem lenne ideje mindenre:
_elfelejti_ visszaállítani a színek és vonalak típusát,
nem mindig jelenít meg minden pontot,
a nyomógombok ki/be kapcsolását nem végzi korrekten (megváltoztatja megnevezésüket, de nem változik meg a felirat).
Remélem, tud valaki segíteni. Szivesen veszek olyan hozzászólást is, amely átirányít mondjuk Qt-ra vagy más grafikához, amelyben nem lesznek ilyen gondjaim :lol:
- A hozzászóláshoz be kell jelentkezni
Ehhez, mi a '"+'"+!/%=%!-nek kell két szál. A GTK++/GLIB timer funkció POMPÁSAN lefedi ezt a kemény multithread-es feladatot...
Amúgy meg idézek a GTK+ FAQ-ból:
5.3. I'm doing some stuff with GTK+ in a separate thread, and properly locking with gdk_threads_enter/gdk_threads_leave() but the display doesn't update properly. [GTK 2.x]
I'm doing some stuff with GTK+ in a separate thread, and properly locking with gdk_threads_enter/gdk_threads_leave() but the display doesn't update properly. [GTK 2.x]
For efficiency, the X window system batches up commands and sends them to the X server in batches instead of sending out immediately.
In a non-multithreaded program, you don't have to worry about this, since the first thing that happens when control returns to the main loop is that any outstanding X requests are sent to the X server.
However, if you are making GTK+ calls from a thread other than the main loop, then GTK+ doesn't know when to send batched commands out. For that reason, after making GTK+ calls in a separate thread, it is usually a good idea to call gdk_flush() before gdk_thread_leave().
Actually, gdk_flush() is more expensive than is necessary here, since it waits for the X server to finish outstanding commands as well; if performance is an issue, you may want to call XFlush() directly:
#include <gdk/gdkx.h>
void my_flush_commands (void)
{
GdkDisplay *display = gdk_display_get_default ();
XFlush (GDK_DISPLAY_XDISPLAY (display);
}
Zsiráf
- A hozzászóláshoz be kell jelentkezni