c++11 multithreading 1<<c++ concurrency in action>>

Source: Internet
Author: User

One, parallel, multi-threaded

1, the computer in parallel there are two ways: task switching, the use of multi-processor multi-core.

Pure task Switching:

Pure Multi-processor multicore:

Task switching is combined with multi-processor multicore:

The actual application is "task switching and multi-processor multicore" mode, first of all hardware offset single-processor single-core elimination "Purely task switching" is no longer, "pure multiprocessor multicore" each core allocation of a process (thread), the number of processes (threads) received a strict limit.

2. Parallel units for programming: splitting tasks into processes or threads

Advantages

Disadvantages

How processes (threads) communicate with each other

C + + standard support

Process

The system has a partial control over its security; can use network communication; communication is simple (high-level interface)

More communication is complex, slow, or even impossible, as the system controls the security of inter-process communication; Slow inter-process switching

Signals/sockets/files/pipes

Whether

Thread

All threads of the same process share the same address space, communication is simple and flexible; fast switching between threads

Data security is difficult to guarantee

Shared address space

Is

the parallel units used by C + + are threads.

Second, why use parallel?

1, to provide a natural way of thinking, simplifying the design;

2, improve performance, you can task parallelism(decomposition of the application into a task),dataparallelism(decomposition of the data into different parts);

Third, when do not use parallel?

Benefits outweigh the disadvantages. Lee: A natural way of thinking, performance, disadvantages: Programming complex, thread switching time-consuming.

Iv. Efficiency of the C + + standard line libraries:

Many programmers who require high performance are usingC + +I was worried .abstraction Penalty, C++in designing the standard library, the standard Committee considered this, especially the line libraries, which they pledged to:there should is little or no benefit to being gained from using the Lower-level APIs directly. Two types of interfaces availableLow-level,High-level,Low-levelAtomic manipulation libraries are available on the new memory model, which can even replace programs that were previously written with a platform-based assembly. High-levelthe interface does not have too manyabstraction Penalty, The standard library promises its functionality with your own handwriting function callLow-levelinterface efficiency, and is well-inline. High-levelmay contain functions you don't need, but don't use them yourself .Low-levelto achieve, outweigh the gains, in usingSTLA proven fact is that the bottleneck lies in the design of your application rather than the implementation of the library.

The example is simple and does not explain.

c++11 multithreading 1<<c++ concurrency in action>>

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.