Re: Allocate/free in main thread, or just the same thread?



Reed Hedges wrote:
[...]
My question is: should glib objects only be allocated/freed in the main
program thread; or, do they just have to be freed by the same thread
that allocated them; or, are there ways to access glib from multiple
threads that I don't yet know about?

It is safe to access a glib object (i.e. GObject) or data structure from
multiple threads the same way its safe to access/modify an integer or string -
as long as you protect the data from yourself simultainiously accessing it
from another thread (i.e. use GMutex and GCond).

If you are accessing data that belongs to GTK+ (i.e. widgets), then
you must share the gdk_threads_mutex with GTK+ (i.e. gdk_threads_enter/leave).

Cheers,
                     -Tristan



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