Re: Gtk and threading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am Montag, den 17.12.2007, 16:01 -0500 schrieb Andres Gonzalez:
> Everybody is saying that all of my Gtk processing should be done in
> the main thread, and indeed, whenever I use a Gtk/Gdk routine in my
> camera thread I get Xlib async errors.  But then how do I trigger a
> render from my camera thread whenever my camera buffer gets a new
> video frame without calling a Gtk/Gdk API routine?

The recommended pattern for passing data from a worker thread to the
main thread, is installing an idle-function with g_idle_add(). The
g_idle_add() function is designed to be thread safe

One variant to achieve that would be:

	static gboolean
	update_canvas_cb (gpointer data)
	{
		gtk_widget_queue_draw (canvas_widget);
		return FALSE; /* remove the callback */
	}

	...
	g_idle_add (update_canvas_cb, NULL);
	...

Notice that you cannot directly connect gtk_widget_queue_draw(), since
that function has no (defined) return value.


> I currently have a common memory buffer that both threads have access
> to. But the Gdk_pixbuf routines seem to be double buffering the data
> so I have to use a Gdk_draw routine to have my common memory rendered.

No need for a shared buffer. Just pass ownership of the picture buffer
to the main thread, by passing it as user_data argument to g_idle_add.
After doing that, the worker thread can discard the pointer:

	g_idle_add (update_canvas_cb, picture);
	picture = NULL; /* ownership passed to main-thread */

Ciao,
Mathias
-- 
Mathias Hasselmann <mathias.hasselmann@xxxxxx>
Openismus GmbH: http://www.openismus.com/
Personal Site: http://taschenorakel.de/

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux