Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

c - Multi-Threading support in c11

The new C11 standard provides a support for Multi-Threading.
My Questions are a bit diversified but definitely answerable.
I have had a look at the C11 n1570 draft.
It says:

support for multiple threads of execution including an improved memory sequencing model, atomic objects, and thread-local storage (<stdatomic.h> and <threads.h>)

What is the Improved memory sequencing model? How/What changes from the c99 Standard?

Rather than just quotes from standard, I will appreciate if someone delves deeper in them and tries explaining the semantics involved.

As I understand, C11 provides support for:

  • Thread creation and Management
  • Mutex
  • Conditional Variables
  • Thread Specific storage &
  • Atomic Objects

I hope I didn't miss anything?
Since now the Standard library itself provides(will provide) all the functionalities needed for Multi-Threading, there would be no need for POSIX and such libraries(for Multi-Threading support) in future?

Lastly, What compilers provide support for the above mentioned features? Are there any references as to timelines when these will be supported?
I remember for C++11 there was a link for compiler support and features, perhaps something like that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First, don't write off C++11. The concurrency work for the new standards was done under the C++11 umbrella, then imported into C11 with the explicit goal of being compatible. While there are some syntactical differences (e.g. due to plain C not having templates or function overloading), semantically they are identical by design. For "evidence" of this, one can check the WG14 papers. E.g:

and references therein. More can be found at Open Std Website

Now, on to your questions:

What is the Improved memory sequencing model?

The obvious answer is that it has been changed to take into account multiple threads and how they interact. For a slightly longer answer, see C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming? that was already mentioned in the comments. For an in-depth understanding, a stackoverflow answer is perhaps not the right place (even less a question with several subquestions!). But luckily Hans Boehm maintains a very good page with interesting links for further reading (again, keep in mind that the C11 and C++11 memory models are semantically identical)

I hope I didn't miss anything?

Together with the memory model, your list seems to cover the concurrency additions in C11. For other changes, wikipedia has a list; of the top of my head I can't come up with anything the wikipedia list has missed.

Since now the Standard library itself provides(will provide) all the functionalities needed for Multi-Threading, there would be no need for POSIX and such libraries(for Multi-Threading support) in future?

Yes, there will be a need for them. First, nobody is going to rewrite all the existing code that uses the various existing thread API's. Secondly, the C(++)11 thread library is/will most likely be implemented as a wrapper around the various native thread libraries; heck, there's even a documented way to retrieve a pointer to the underlying native thread, in case one needs to do something beyond what the C(++) thread library supports. Think of the C(++)11 thread library more like a portable, least common denominator wrapper around the various native thread libraries.

Lastly, What compilers provide support for the above mentioned features? Are there any references as to timelines when these will be supported? I remember for C++11 there was a link for compiler support and features, perhaps something like that?

I haven't seen any detailed list, there doesn't seem to be as much buzz around C11 compared to C++11. There's a short notice for the upcoming GCC 4.7 here: http://gcc.gnu.org/gcc-4.7/changes.html . For the concurrency support, one can check the support for concurrency in the C++11 status page here: http://gcc.gnu.org/projects/cxx0x.html . There's also some notes on the current status and plans for GCC at http://gcc.gnu.org/wiki/Atomic (according to that page, stdatomic.h is available). For other compilers, there's a nice list of the C++11 status for various compilers here http://www.aristeia.com/C++11/C++11FeatureAvailability.htm . From the links there one can check the status of the concurrency support, and assuming that the vendor in question plans to support C11, the C11 concurrency support is then likely to be at about the same level.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...