Thread initialization and condition



Hello,

I have a problem while running a thread application. Here is my code:

Download::Download ()
{
  thread = Glib::Thread::create (sigc::mem_fun (*this,
           &Download::threadFunc), true);
}

void Download::fetch ()
{
  // queue new files to download...
}

void Download::loop ()
{
  do
  {
    // download new files
  }
  while (1)
}

Ok, this was working on one machine. But now while testing it on
another machine (also Linux) I got other results. This is how I use it:

  Download dl;
  dl.fetch (m_url, m_file);

If I do debugging or print some debug messages I see that on one
machine the thread loop() is entered before the fetch() function. I
would expect that. But on the other machine the fetch() function is
called before the thread loop().

Couldn't I trust gtkmm that the thread loop is constructed and entered
after returning the Glib::Thread::create() call?

I tried to use some conditions to wait until the thread has entered. It
worked, but only on one machine. The other one blocked forever. If this
is a defined behaviour that I need to think about a more complex
condition mechanism at initialization time.

Gentoo:
- gtkmm-2.10.10
- thread loop() is called *before* fetch()

Ubuntu:
- libgtkmm-2.4-1c2a 1:2.12.0-0ubuntu1
- thread loop() is called *after* fetch()

Any ideas about that problem?

regards
Andreas


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