Study notes "C ++ concurrent programming combat" (1) - concurrent basis

What is complicated by:
    Two or more separate events occur simultaneously, for single-core task switching is also considered to be concurrent.
    At present really significant is the concurrent hardware for multi-core multi-threaded task, complicated by the degree depending on the available hardware concurrency.
    Certain task switching overhead context switch, to save the current state of the CPU, PC, instructions, etc.
    Early treatment need to reload the same state when switching back to other tasks, such as cache memory load.
    In addition there are some differences in concurrency and parallelism.
    
Concurrent way:
    More complicated process: an independent mission inter-process and transmit information via inter-process communication.
        Advantages: relatively independent, occupy separate space, relatively safe. Also through the network
           Interprocess communication to communicate, sometimes parallel increase availability and performance scalability.
        Disadvantages: process start-up cost is relatively large, and take up more system resources, communicate with each other more complicated or slower.
    Multithreading: execute multiple threads within a single process, between threads can share the process address space.
    
Why Concurrency:
    Separation of concerns: separation of different design and implementation, logical or functional tasks, such as to a clear design or response, such as GUI development.
    Performance: the ability to take advantage of multi-core and improve concurrency, such as the division of tasks to execute concurrently to save time overhead.
    The division of tasks that may arise during the task parallelism, data parallelism two levels. Data Parallel data may need to be carefully designed to parallel processing.

Why not use concurrency:
    When less than the cost of benefits. As the complexity of concurrent maintainability, the overall effect of concurrent execution threads start and manage threads, thread switching overhead and so on.
    
C ++ 11 threading library
    Multithreading (system API) under different platforms using different systems there is a certain level tools often achieve concurrency,
    C ++ threads library of 11, due to the different platforms abstraction extra execute some code, and therefore there will be some impact on performance;
    Except in special circumstances, C ++ achieve 11 standard thread library has been good enough, or using only low-level platform-specific tools.
    Further C ++ API tool. 11 and the corresponding threads can use different platforms (C ++ nativa_handle 11) of binding.

 

Guess you like

Origin www.cnblogs.com/haomiao/p/11647376.html