1.3 Parallel and multi-threading in C + +

Source: Internet
Author: User

Standardized support for multithreaded parallelism is a new thing for C + +. Only in c++11 can you write multithreaded programs that do not depend on the system extension library. In order to understand the new C + + line libraries, it is important to know his history.

1.3.1 C + + multi-Threading history

The 1998 C + + standard was unaware of the existence of threads, which resulted in many programs being written in a sequential structure. Not only that, the memory model does not have a standard definition, so you leave the specified compiler cannot write multi-threaded 1998c++ with the.

Of course, compiler vendors can add extensions to languages for free, and the popularity of multithreaded C APIs-such as the POSIX C standard and Microsoft Windows api--has led C + + compiler vendors to support multithreaded extensions, and compiler support is typically limited to allowing the C API to use this platform to let c+ + Runtime is working under multiple threads. Although few compilers provide a formal multithreaded memory model, compilers and processors can already support multithreaded C + + programs well.

The C API that uses a specific platform is not satisfied with multithreading. C + + programmers have relied on their class libraries to provide object-oriented multithreading support, such as the MFC program framework and multipurpose C + + libraries, such as Boost and Ace, which have encapsulated the underlying API and provide more advanced multithreaded tools for simplifying tasks. Although class libraries are diverse, especially when starting new threads, there are many similarities in the structure of classes. The C + + class library is a very important and helpful programmer's design, and the use of RAII (resource allocation initialization) locks ensures that the mutex is open when it leaves the range.

In most cases, the compiler unites platform-specific APIs and cross-platform class libraries such as Boost and Ace as a solid foundation for using C + + write multithreaded, but a lack of standards means that a lack of thread-aware memory models can cause problems, This is especially the case when you want to use the processor to improve program performance or the compiler's cross-platform across various platforms.

1.3.2 synchronization support for new standards

All of the changes have been made with the release of C++11, not only with a brand new thread-aware memory model, but also by the C + + standard library, which already contains classes for managing threads, shared data with protection, inter-thread synchronization, and underlying atomic operations.

The new C + + line libraries is largely based on the preceding C + + class library. In particular, the Boost line libraries becomes the original model for the new class library, and many of the classes ' names and structures are an upgraded version of boost. Since the new standards have been formed, this is a two-way flow. The Boost class library has made his own changes in many ways to adapt to the new C + + standard, so users from boost-over should find a lot of similarities.

One of the new standards for synchronizing support knowledge, there are many areas of language strengthening that make programmers feel easier to write. Although this is beyond the scope of this beginning, these changes have directly affected the line libraries and the way it is used. Appendix A provides a concise introduction to these language features.

The support of atomic operations allows programmers to write more efficient programs without using the platform-specific extension language, which is a truly efficient and portable code that the compiler needs not only to test the platform, but also to consider optimizing operations to make the program optimal.

1.3 Parallel and multi-threading in C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.