GNOME Bugzilla – Bug 755091
multithread example: Use the C++11 concurrency API.
Last modified: 2015-11-26 11:33:31 UTC
Created attachment 311429 [details] [review] 0001-multithread-example-Use-std-thread-etc-instead-of-Gl.patch Does this patch look OK?
We will need to update the text in the book too. Maybe it can be simplified now that we don't need to worry about problems specific to Glib::Thread.
> Does this patch look OK? It looks OK, but it does not work OK. The program crashes, if the Quit button is pressed while the worker thread is running. I don't know why. I can probably find out why it crashes. > We will need to update the text in the book too. Maybe it can be simplified > now that we don't need to worry about problems specific to Glib::Thread. A very small part of the listed problems is specific to Glib::Thread. Most problems are specific to sigc::trackable, and the rest of libsigc++, not being thread-safe. Only the last part of rule 4 at https://developer.gnome.org/gtkmm-tutorial/stable/sec-the-constraints.html.en is specific to Glib::Thread.
(In reply to Kjell Ahlstedt from comment #2) > The program crashes, if the Quit button is pressed while the worker thread is running. I guess the std::threads need to be detach()ed or possibly join()ed. I'll take a look.
Created attachment 313644 [details] [review] patch: multithread example: Use std::thread, etc, instead of Glib::Threads::*. The problem is that the thread is joined twice. If m_WorkerThread->join(); is replaced by if (m_WorkerThread->joinable()) m_WorkerThread->join(); the program does not crash. Contrary to Glib::Threads::Thread, std::thread must be deleted, if we want to avoid a memory leak. I have fixed that too. I've also replaced Glib::usleep() by std::this_thread::sleep_for(). That's not necessary.
Created attachment 314967 [details] [review] 0001-Multi-threaded-chapter-Remove-warnings-about-sigc-sl.patch This small patch updates the text in the "Multi-threaded programs" chapter. It mostly just removes the mentions of creating a thread with a sigc::slot, because we don't do that with std::thread. Let's push these patches when we have deprecated Glib::Threads, when we can require C++14: https://mail.gnome.org/archives/gtkmm-list/2015-August/msg00062.html And let's do that after we have branched, after our move operations changes have settled down.
I have pushed these patches to master.