Re: Thread initialization and condition



En/na Andreas Volz ha escrit:
> 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
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 
> 

This looks like that there is no synchronization between main thread and
the FTP thread. The FTP thread should be waiting till main thread has
posted a new file to download and then start download.

GLibmm provides mutex and mutex-conditions to implement a
producer-consumer relation between threads.

Joaquim Duran
Thanks and Best Regards,


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