Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt concurrency memory model C++11
Hey Qt folks,
I've got a general question on Qt's implementation of concurrency (i.e. QThread et al.).
The new C++ standard introduces a whole new way of concurrency, incorporating a new memory model making it unnecessary to use 3rd party libs like pthread, for instance.
As far as I know, Qt is currently using the pthread-library - in case of linux - within all concurrency related classes.
Will Qt make use of the new memory model and the new Thread API of the new C++ standard in future releases? Are there any plans/roadmaps?
Thanks in advance.
Hi and welcome to devnet,
You should rather post that question on the interest mailing list, you'll find there Qt's developers/maintainers. This forum is more user oriented
Thanks! I posted to the interest mailing list.
What do you mean by "memory model"?
Note that std::thread only provides a high-level abstraction layer. On POSIX systems (e.g. Linux), a std::thread is simply a wrapper for a pthread. For example, the function
pthread _thandle! http://en.cppreference.com/w/cpp/thread/thread/native_handle
In short, std::thread uses pthread similarly to how QThread uses pthread. It removes the requirement for you to write pthread-specific code, but it doesn't remove your program's dependency on pthread.
bq. Of course, you can write multi-threaded code in practice for particular concrete systems -- like pthreads or Windows. But there is no standard way to write multi-threaded code for C++98/C++03.
bq. The abstract machine in C++11 is multi-threaded by design. It also has a well-defined memory model; that is, it says what the compiler may and may not do when it comes to accessing memory.
Maybe my expectations on that memory model are too high and libpthread is the "one" who implements the model and makes all the work at the end of the day.
But I'm certain that something is different (maybe better) in C++11 when it comes to concurrency and my question is: Will Qt incorporate that?
c++11 memory model is a set of rules what compiler can do and what it can't when it comes to threads. Before there was no such thing as thread in the language dictionary.
But threading is not something new and there were ways to do it before c++11 via external libraries, either OS provided (e.g. WinAPI CreateThread) or POSIX. Qt builds on top of these.
There is nothing to incorporate for Qt. It already did threading for years. What's new in c++11 is that you can reason about threading in terms of language specs and not 3rd party libraries.
The std::thread etc. are not the memory model. The model is just that - a model. It defines what can be moved around in relation to memory barriers. It also says which operations (in the threading context) have undefined behavior. Threading libraries like QtConcurrent, pthreads, std::thread, WinAPi threads (some of which are the same thing) already do that.
The memory model is just a set of rules that were already there and used widely, just never formally specified and acknowledged by the language. Now they are and have library primitives building on top of that.
There is no benefit right now to rewrite Qt to use std:: primitives. It would be just switching from red apples to green.