On Tue, 26 Oct 2010 22:41:44 +0000
Juan Pablo L. <jpablolorenze...@hotmail.com> wrote:
> Hello, i m using threads in a glib-only project, a service daemon, i
> have implemented them using GThreads, but i see now that GThreads is
> only a wrapper around pthreads (with the corresponding overhead from
> doing so) and does not provide any additional benefit (if i dont
> mistake the only real benefit is the cross platform feature).
[snip]

I doubt very much you will notice any difference.  Compared to the
overhead of starting new threads and potential contention on mutexes,
wrapping costs are likely to be negligible.  There is a case for using
pthread directly if you are using your own wrappers for automatic
lifetime management and exception safety in, say, C++, or if you want
to use thread cancellation, or the small number of other features
supported by pthread but not by GThreads.

> 1. if i dont issue the g_thread_init, at the beginning of my
> application, will there be any problem in glib itself? some functions
> or functionality willl cease to work or work incorrectly ?

You must call g_thread_init() if more than one thread might call glib
functions in order to make glib thread safe.  So call g_thread_init() in
a multi-threaded program.

> 2. Can i
> just use Glib with pthread instead of GThread ? i know that the main
> loop and GAsyncQueue will work out of the box.

Yes, provided you have called g_thread_init().

> 3. The documentation
> says that by issuing g_thread_init Glib will become thread safe, i
> dont understand this, if i dont issue the command Glib will not work
> in a multithreated environment ?

It won't, no.  See above.

> 4. If in the future i use glib in
> another project and decided to use pthread in my code but i know GTK
> uses GThread inside, will this be a problem? will it be overhead
> because i would be using pthreads and GThread together ?

No.  As you have already deduced, GThread is a wrapper for pthread in
unix-like environments.

Chris


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

Reply via email to