GTK & threading on FreeBSD (and possibly other unices)



Hi,

After getting a bit more intimate with FreeBSD's implementation of
POSIX threads I had another stab at getting gFTP to work.

The problem I had (after fixing a rather simple compile error with
include files) is that file-transfers (which get their own thread) just
weren't moving. Except when I was doing stuff with the interface.

After checking gFTP's code I found that all it is rather well coded for
threading, and was using sleep(0) in all the right places. So I had a
look at the main loop, which was gtk_main(). Now that (AFAIK) doesn't
use a sleep(0). So I added it, and presto, gFTP ran as smooth as a
newborn baby.

What I did exactly was in gtkmain.c at line 476 I added:

  if (g_main_is_running (main_loops->data))
    {
      GDK_THREADS_LEAVE ();
      sleep(0);
      g_main_run (loop);
      GDK_THREADS_ENTER ();
      gdk_flush ();
    }

Now I'm pretty new to GTK's internals, so I'm not sure if the sleep is
in the right place or not.

The way I figured is:
  - It should NOT be outside the LEAVE/ENTER statements, because they
translate to unlock and lock mutex. Sleeping after a lock and before an
unlock seems unhealthy to me 
  - The gdk_flush should probably follow the g_main_run(loop) ASAP (not
sure what it does)

And BTW, unistd.h needs to be added to the includes at the top for the
use of sleep.

Them were my $0,02

            DocWilco



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