After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 755091 - multithread example: Use the C++11 concurrency API.
multithread example: Use the C++11 concurrency API.
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: documentation
3.17.x
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on: 757674
Blocks:
 
 
Reported: 2015-09-16 06:47 UTC by Murray Cumming
Modified: 2015-11-26 11:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-multithread-example-Use-std-thread-etc-instead-of-Gl.patch (5.31 KB, patch)
2015-09-16 06:47 UTC, Murray Cumming
none Details | Review
patch: multithread example: Use std::thread, etc, instead of Glib::Threads::*. (6.24 KB, patch)
2015-10-19 08:29 UTC, Kjell Ahlstedt
none Details | Review
0001-Multi-threaded-chapter-Remove-warnings-about-sigc-sl.patch (3.18 KB, patch)
2015-11-06 10:01 UTC, Murray Cumming
none Details | Review

Description Murray Cumming 2015-09-16 06:47:23 UTC
Created attachment 311429 [details] [review]
0001-multithread-example-Use-std-thread-etc-instead-of-Gl.patch

Does this patch look OK?
Comment 1 Murray Cumming 2015-09-16 06:56:27 UTC
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.
Comment 2 Kjell Ahlstedt 2015-10-18 08:15:30 UTC
> 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.
Comment 3 Murray Cumming 2015-10-18 09:46:02 UTC
 (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.
Comment 4 Kjell Ahlstedt 2015-10-19 08:29:35 UTC
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.
Comment 5 Murray Cumming 2015-11-06 10:01:50 UTC
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.
Comment 6 Murray Cumming 2015-11-26 11:33:31 UTC
I have pushed these patches to master.