GThread system may only be initialized once

Bug #190291 reported by Matthias Adler
2
Affects Status Importance Assigned to Milestone
Me TV
Won't Fix
Low
Unassigned

Bug Description

Hi,

I'm failing to launch me-tv (0.5.9) on a Fedora (8) machine. Me-tv will crash everytime due to some threading issue. All this happens on a dual core2 intel machine, with a non-64 bit 2.6.23.14 kernel. Gnome is at 2.20.2, GTK2 at 2.12.5. All dependencies at compile-time were met - or at least autogen / gcc did never complain about anything missing.

Description of problem:
The main window appears, but soon after the application crashes. There is no way to interact with the application before the crash takes place. From what I can tell it has something to do with GThread, but I haven't had the time yet to digg any deeper. Started from the command line, me-tv will last output "GThread-ERROR **: GThread system may only be initialized once. aborting... " before crashing. Detailed Debuginfo file is attached.

How to reproduce:
Launch me-tv (may have to create initial config files)
Wait for Main Window to appear
App will crash

I'll gladly provide any further information needed to resolve this issue.

Cheers,

Matthias

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :
Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Hi Matthias,

I just released 0.5.13 yesterday and would like you to take a look at it, if you've got the time. There were several issues <= 0.5.12. Are you packaging for Fedora?

Changed in me-tv:
assignee: nobody → michael-lamothe
importance: Undecided → High
milestone: none → station-5
status: New → In Progress
Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Hello again,

I have tried 0.5.13, 0.5.14, and the recently released 0.5.15, but unfortunately the above problem persists. I'll keep at it and will try a few things in the coming days. But in the end, it wouldn't come as a total surprise if my particular usb dvb device (cynergy xs hybrid) or pulseaudio is the dealbreaker here. Debugging this issue might take some time.

I'm not packaging for Fedora officially, but could very well imagine to do so. Me-Tv looks very promising to me and appears to be more than just on feature *parity* level compared against Kaffeine when it comes to dvb. Basically, I'd love to see it hit the repositories any time soon.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :
Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :
Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Hi Matthias,

The nature of the error message "GThread system may only be initialized once" would suggest that it is an issue with my code. It's a tough one.

If Me TV generates a ~/.me-tv/me-tv.config can you please change the "xine.video_driver" to "xshm" and try that, hope you like XML ;). I'm wondering if it's your video driver. You can modify the audio driver with "xine.audio_driver" if you know a better one. Finally, if that all fails, modify the "engine_type" to "none" just to see if the application can start that way.

There's a preferences window in the application that can drive these settings but obviously you can't get to that.

Thanks,

Michael

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Hi Micheal,

Me Tv generated a config file, so I was able to check out your suggestions. XML editing is OK with me ;)

Altering the audio and video driver options did not yield any positive results. The options I tried for audio: none, auto, alsa, sdl, pulseaudio. Video options checked: auto, xv, opengl, xshm, xxmc, sdl.

I then changed to engine_type value to 'none' ( <add key="engine_type" value="none"/> ) and voila, the app started and worked. Yay ! Preferences can be set from within Me TV, EPG seems to be OK, recording works. Only watching TV won't work this way, of course.

Cheers,
Matthias

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

A version of application.cc that checks that the Application class only gets instantiated once.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

You seem to know what you're doing, so here's another thing to try. Are you able to try this application.cc file for me? Let me know if you need more.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Well, I applied the patch yesterday and the conditional 'if (current_application != NULL)' in the main Application class gets fulfilled. Therefore, it raises the exception "Application class can only be instantiated once" and havoc thereafter ensues (see attached log file) with the CPU spinning 100% until the Me TV process is terminated.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Ok, that was my bad. Please try this one.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Hi, I tried the second application.cc you attached, and this time the exception "Application class can only be instantiated once" is not triggered. The threading issue remains, though. The debug trace looks pretty much the same.

Then, I fired up Anjuta and added debug messages in various parts of the source code. So far, I narrowed the problem down to line 97 in main_window.cc ( engine = new XineEngine();). If I commented the line out, Me TV would start without a problem. So, I altered the code a bit:

if (engine_type == "xine")
 {
  // catch engine init failure
  TRY
    engine = new XineEngine();
  CATCH
   // throw Exception("Could not initialize MainWindow::engine");
                       Log::write("Could not initialize MainWindow::engine");
   engine = NULL;
 }

I'll try to take a look at xine_engine.cc, maybe I can find something (but I don't know much about C++ ).

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Ok, here's what I've found. It seems to be crashing because one of your xine plugins (input_gnome_vfs) is trying to initialise the GThread system but I've already done that in Me TV. On Debian/Ubuntu the input_gnome_vfs plugin comes from the libxine1-gnome package. If you uninstall libxine1-gnome then I assume input_gnome_vfs won't load which might test my theory.

What version of libxine are you running? Or maybe you're using xine-lib?

Thanks,

Michael

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Your theory is correct, the GTread issue is caused by a xine plugin. On Fedora the problematic plugin is called 'xine-lib-extras' (version 1.1.10.1) and the descriptions says:
This package contains extra plugins for xine-lib:
  - EsounD
  - JACK
  - Pulseaudio
  - GDK-Pixbuf
  - GNOME VFS
  - SMB
  - SDL
  - AA-lib
  - Libcaca
  - Image decoding
  - DirectFB output

I uninstalled this package and Me TV works without any problem (so far).

Here's a list of all installed xine-lib packages:

xine-lib-1.1.10.1-1.fc8
xine-lib-extras-nonfree-debuginfo-1.1.10.1-1.lvn8
xine-lib-extras-1.1.10.1-1.fc8 (removed)
xine-lib-arts-1.1.10.1-1.fc8
xine-lib-devel-1.1.10.1-1.fc8
xine-lib-extras-nonfree-1.1.10.1-1.lvn8

Cheers,

Matthias

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

So that's kind of fixed. But this is not ideal. I wonder how other applications such as gxine and totem get around this issue.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

It has to be an issue in the plugin. They should be using,

 if (!g_thread_supported ())
 {
  g_thread_init (NULL);
 }

Me TV does this but it's the first one to call it. Maybe this is a bug in 1.1.10, I'm still on 1.1.8.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Does this issue not arise on Ubuntu if the 1.1.8 gnome_vfs plugin is installed ? If not, this could indeed be a problem with 1.1.10, or a packaging issue with Fedora (they apply a 67.8 KB patch to the xine-lib source for building the rpm).

I downloaded the source rpm for xine-lib and subpackaged xine-lib-extras into smaller bits. Everything is fine, unless the plugin "xineplug_inp_gnome_vfs.so" is installed (for whatever reason the smb plugin works flawlessly). The file 'input_gnome_vfs.c' uses (line 367)

if (!g_thread_supported ())
  g_thread_init (NULL);

only they do not have curly braces around the conditional, and patching the file so there is, does not change anything about the outcome. The comment in the head of the file in line says 'this file is part of totem' (line 5). I tried gxine, but it would not accept my channels.conf for no apparant reason. If the gnome_vfs plugin is installed, gxine launches and plays back videos, though. I haven't yet tried totem-xine.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Oh, gxine expected the channels.conf file to be in the .xine not in the .gxine directory ... so, watching tv in gxine works with input_gnome_vfs plugin installed.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Tested Me TV with xine-libs v. 1.1.8 and the GThread issue happens still. Maybe I should file a bug in Fedora bugzillla and see what turns out ...

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

I have all available xine plugins installed on Ubuntu 7.10 and I don't get the issue.

Maybe gxine doesn't initialise the GThread library, I'll check when I get home.

Here's an idea, can you please comment out the g_thread_init (NULL); line in Me TV and see if it still runs?

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

And here's another sanity check to try. Put 2 iterations of the GThread initialisation code. i.e.

 if (!g_thread_supported ())
 {
  g_thread_init (NULL);
 }
 if (!g_thread_supported ())
 {
  g_thread_init (NULL);
 }
 gdk_threads_init();

This works fine for me. If this fails for you then we know that g_thread_supported() is not doing its job.

BTW, removing both of them causes a nice runtime error on my system.

Thanks for all your help. It's nice dealing with people that know their stuff and aren't afraid to get their fingers dirty. I really hope that we can get this working for Fedora.

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

You're welcome ;) And I think we are getting close ...

If I put the 2 iterations in, Me TV still crashes with vfs-plugin installed. But then I commented out all function calls to g_thread_init() AND gdk_threads_init() so it looks like this:
if (!g_thread_supported ())
 {
// g_thread_init (NULL);
 }
 if (!g_thread_supported ())
 {
// g_thread_init (NULL);
 }
// gdk_threads_init();

after that Me TV starts and works. Yeah!

After that I looked through the GLIB Reference Manual (installed 'DevHelp'). There I stumbled upon this note:

<from manual>
g_thread_init() might only be called once. On the second call it will abort with an error. If you want to make sure that the thread system is initialized, you can do this:

if (!g_thread_supported ()) g_thread_init (NULL);

After that line, either the thread system is initialized or, if no thread system is available in GLib (i.e. either G_THREADS_ENABLED is not defined or G_THREADS_IMPL_NONE is defined), the program will abort.
</from manual>

So I wrapped the thread init code in an #ifndef macro (not sure about the G_THREADS_IMPL_NONE part).
#ifndef G_THREADS_ENABLED
 // #ifdef G_THREADS_IMPL_NONE
 if (!g_thread_supported())
 {
     g_thread_init (NULL);

    }
    gdk_threads_init();
 // #endif
 #endif

Now Me TV will work with either xine's vfs-plugin installed or not installed. I don't know if this makes any sense ... It appears g_thread_supported() is the culprit here. The information from the GLIB Reference Manual indicate that glib might be compiled with out thread-safety on Fedora.

Cheers,
Matthias

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

So g_thread_supported() is the issue it seems and both Me TV and VFS plugin are doing the right thing. Me TV will not run without thread support, there's a thread that reads off the DVB device to write to the xine renderer, if that doesn't start you will not see video. I would guess that Glib thread support _is_ installed because your "#ifndef G_THREADS_ENABLED" will remove those lines so it will be same case that you had when you commented out the lines previously. Therefore G_THREADS_ENABLED is _defined_ which it should be.

If you like I can write you a small program to test this.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Ok, I've found this bit of text,

  "To use g_thread_init() in your program, you have to link with the libraries that the command pkg-config --libs gthread-2.0 outputs"

at http://library.gnome.org/devel/glib/stable/glib-Threads.html

This is my bad and will fix it now. Hope that this resolves the issue.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Ready for 0.5.19 waiting for test confirmation from Matthias.

Changed in me-tv:
status: In Progress → Fix Committed
Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Released in 0.5.19.

Changed in me-tv:
status: Fix Committed → Fix Released
Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Hi,

tested release 0.5.20 and unfortuately the threading issue is still there. As noted before, Me TV works for me like a charm even if I alter the application.cc file like this:
 if (!g_thread_supported ())
 {
  //g_thread_init (NULL);
 }
      // gdk_threads_init();
      // gnet_init();
      // GDK_LOCK;

Really, watching and recording TV, EPG, etc., everything works _with_ threading. At the moment I do not know why. (see attached screencast)

Let's put this issue in the background for a while. I build a rpm which is about to be released into the wild soon. If others confirm that they experience the same threading issues, like those happening on my machine, I could alter the rpm with above changes and see if that is solving the problem for them, too. After all, the xine-vfs plugin triggers some magic in the whole glib/gtk/gnome stack.

For the next few days, I'll just *use* Me TV with these changes to the source code, so I can come up with ideas for blueprints what features would be cool to have in Me TV.

Cheers,
Matthias

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote : Re: [Bug 190291] Re: GThread system may only be initialized once

Yeah, it might be a good idea to talk to a few guys on your side
(Fedora) to see if anyone has had similar issues.

To summarize, from what I can tell both the VFS input plugin and Me TV
are doing the right thing but g_thread_supported () does not work
properly on your setup. I can confirm that it works here.

Let me know if there's anything I can do to help. Good luck.

Thanks,

Michael

On 24/02/2008, Matthias Adler <email address hidden> wrote:
> Hi,
>
> tested release 0.5.20 and unfortuately the threading issue is still there. As noted before, Me TV works for me like a charm even if I alter the application.cc file like this:
>
> if (!g_thread_supported ())
> {
> //g_thread_init (NULL);
> }
>
> // gdk_threads_init();
> // gnet_init();
> // GDK_LOCK;
>
> Really, watching and recording TV, EPG, etc., everything works _with_
> threading. At the moment I do not know why. (see attached screencast)
>
> Let's put this issue in the background for a while. I build a rpm which
> is about to be released into the wild soon. If others confirm that they
> experience the same threading issues, like those happening on my
> machine, I could alter the rpm with above changes and see if that is
> solving the problem for them, too. After all, the xine-vfs plugin
> triggers some magic in the whole glib/gtk/gnome stack.
>
> For the next few days, I'll just *use* Me TV with these changes to the
> source code, so I can come up with ideas for blueprints what features
> would be cool to have in Me TV.
>
> Cheers,
> Matthias
>
> ** Attachment added: "Me TV works though 4 things commented out"
> http://launchpadlibrarian.net/12164365/Me-TV-works.ogg
>
>
> --
> GThread system may only be initialized once
> https://bugs.launchpad.net/bugs/190291
>
> You received this bug notification because you are a bug assignee.
>

Changed in me-tv:
importance: High → Low
status: Fix Released → In Progress
Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Over to you.

Changed in me-tv:
assignee: michael-lamothe → matthias-bitshaker
Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Setting this to incomplete until we get more info.

Changed in me-tv:
status: In Progress → Incomplete
Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Hi,

sorry for the long time no see. The package for Fedora is still in the "review queque" and so far it does not look like anyone has taken a look at it. Anyone interested @see: http://bugzilla.livna.org/show_bug.cgi?id=1905

In the meantime there have been a few kernel and xine-lib updates: Currently kernel 2.6.24.3 (+ patches from 2.6.25) and xine-lib 1.11.1, but the problem still retains (for me).

For everyone bold out there (and having a spare Fedora system available), the rpm is located here: http://files.bitshaker.net/me-tv/me-tv-0.5.25-1.fc8.i386.rpm. I'll appreciate any feedback.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Ha, good luck with that. I'll see if I can find a Fedora 8 disk on the front of a magazine tomorrow.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Hi Matthias,

I've installed Fedora 8 but I'm completely lost on how to use the system. i.e. where do I get libxine from. Can you please help? How do I contact you?

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Moving this off the radar because we don't know what the issue is and it seems unlikely that it'll be fixed (if Me TV is the source of the issue) for the 0.5 series.

Changed in me-tv:
milestone: station-5 → none
Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

In 0.6, I'm using GStreamer so this will not be an issue.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Well, 0.6 just released and I had to use Xine. GStreamer just doesn't seem to be "up to it". Have you heard anything from your guys?

Revision history for this message
Matthias Adler (matthias-bitshaker) wrote :

Whew, how fast time can pass at times ... and yeah, gstreamer is not there *yet*.

Unfortunately, there has not been shed more light on this issue since when I reported it. The repository maintainers told me that this must be resolved, before they would approve my package. I was checking out 0.6 this afternoon, but there seems to be a runtime problem with glibmm (at least on my main machine). I'll open up another report for this specific issue.

I hope 0.6 will no longer cause any threading problems of this kind. As we found out earlier, input_gnome_vfs is/was the culprit here, and with the introduction of gio the former is obsolete anyways.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

Wait for 0.6.1.

Revision history for this message
Michael Lamothe (lamothe-deactivatedaccount-deactivatedaccount) wrote :

If you don't mind I might shut this down because you said that the thing that caused it will soon be obsolete. We can just open this back up again if it continues to fail.

Changed in me-tv:
assignee: matthias-bitshaker → lamothe
milestone: none → station-6
status: Incomplete → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.