After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 149490 - Need to call g_thread_init when using message logging and threads
Need to call g_thread_init when using message logging and threads
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: docs
2.3.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-08-06 12:07 UTC by Vincent Untz
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Small test case (1.54 KB, text/plain)
2004-08-06 12:10 UTC, Vincent Untz
Details

Description Vincent Untz 2004-08-06 12:07:33 UTC
When you use message logging (via g_log et al) and you are using threads, things
don't work well unless you called g_thread_init().

This is not a problem if you're using gthread (because then, you'll call
g_thread_init), but if someone don't use gthread and directly uses pthread, then
he might find a crash like this if he uses g_log from two threads:

"(process:608): MyLogDomain-LOG-0x100 (recursed): my log message
 
aborting..."

As explained in [1]:

'the "(recursed)" part above indicates that g_log() was called from within
a handler of g_log() within the same thread.'

The problem here is probably that glib doesn't seem to know that there are
multiple threads. Adding g_thread_init (NULL) make it work.

This should probably be written down somewhere in the docs.

[1] http://mail.gnome.org/archives/gtk-devel-list/2001-June/msg00446.html
Comment 1 Vincent Untz 2004-08-06 12:10:40 UTC
Created attachment 30275 [details]
Small test case

This is a small test case to see the crash.
Comment 2 Owen Taylor 2004-08-06 14:47:33 UTC
I guess I'm just misunderstanding something abou thtis bug report....
you tried to use GLib from a threaded app without initializing
threads and didnt' work... 

There's nothing different about g_log() than any other GLib
function.
Comment 3 Vincent Untz 2004-08-06 15:10:03 UTC
I'm just saying that people might not use GThread but directly pthread. If they
use pthread, how should they know that they have to call g_thread_init()? If I'm
using threads, should I always call g_thread_init()? Even if I don't use any
g_thread_*() function?

From the documentation of g_thread_init():
"Before you use a thread related function in GLib, you should initialize the
thread system. This is done by calling g_thread_init()."

But if I just use g_log*() functions (as in the sample I attached) and no other
GLib functions, I don't use any thread related function in GLib. Or maybe I'm
not correctly understanding "thread related function in GLib"?

(you may say that people using threads and GLib should use GThread, but as far
as I understand it, it's not an obligation and just a recommendation)
Comment 4 Owen Taylor 2004-08-06 19:09:39 UTC
OK, that g_thread_init() comment needs to be changed to

 "If you use GLib from more than one thread, you must initialize
  the thread system by calling g_thread_init()"

All sorts of parts of GLib need locking to be initialized
to work in a threaded application.
Comment 5 Matthias Clasen 2004-08-12 15:00:50 UTC
Changed the docs.