[C #] Concurrency in C # Cookbook (1)-concurrent programming overview,

Source: Internet
Author: User

[C #] Concurrency in C # Cookbook (1)-concurrent programming overview,
Concurrent Programming Overview

We often hear in our ears about terms such as high performance, concurrency, and parallelism, and many people have some misunderstandings about concurrent programming.


Misunderstanding 1: Is concurrency multi-thread?
A: multithreading is only one form of concurrent programming. There are many types of concurrent programming: asynchronous, parallel, TPL data streams, and responsive programming.
Misunderstanding 2: only large server programs need to consider high concurrency?
A: concurrent programming should be considered for commonly used desktop applications, mobile applications, and B/S applications. The quality of life of modern users is generally improved, and bandwidth is also growing, user requirements are becoming increasingly demanding. Users' requests must be promptly and quickly responded to, and the loss of users is inevitable for enterprises that cannot meet such requirements.
Misunderstanding 3: Concurrent Programming is complicated, but is it a master's patent?
A: No! No! No! In long ago, it may be right. At that time, it was indeed a masterpiece of senior programmers. But now, writing asynchronous code from the async/await keyword introduced by. NET 4.5 has become very easy.

 

1.1 concurrent programming

1. Concurrency: perform multiple tasks at the same time.

-- With concurrency, the database can be read and written while responding to user input;
-- With concurrency, the server can process multiple requests at the same time;
-- If the program you want to write can do multiple tasks at the same time, you need to use the Concurrency Technology.

 

2. multithreading: a form of concurrency. Multiple Threads are used to execute the program.
-- Multithreading is only a form of concurrency, not a unique form. From. NET 4.5, we should use more advanced abstraction mechanisms to make programs more powerful and more efficient.

  

[Note] Once you enter new Thread (), the code in the project is out of date.

 

3. Parallel Processing (Parallel Programming): divides a large number of ongoing tasks into small pieces and assigns them to the concurrent running threads.

-- Multithreading is required in the thread pool, which stores the task queue and can be adjusted as needed. Correspondingly, another form of concurrency is generated: parallel processing.
-- We hope to maximize the CPU utilization and achieve parallel processing through multiple threads. The CPU of a modern PC is more than 4 cores. If only one core is used to execute the task, it is not a waste of resources if other cores are idle.
-- Divide tasks into small pieces through parallel processing and allocate them to multiple threads so that they can run independently on different cores.
-- Parallel processing is one of multiple threads and multiple threads is one of concurrency.

 

4. asynchronous programming: a form of concurrency. It adopts the future mode or callback mechanism to avoid unnecessary threads.
-- The core concept of asynchronous programming is asynchronous operations: the started operations will be completed after a period of time. When this operation is being executed, the original thread will not be blocked. Start the thread of the change operation and continue to execute other tasks. When the operation is completed (the method call is completed), the future of the method will be notified, or the callback function notification program will be called.

 

5. responsive programming: A Declarative Programming mode in which the program responds to time.
-- Unlike asynchronous programming, asynchronous programming is based on asynchronous operations, which are based on Asynchronous events. Asynchronous events can occur multiple times at any time without an actual "start", such as user input.
-- If you think of a program as a powerful state machine, the behavior of the program can be seen as its response to a series of events, that is, every time an event is triggered, the state is updated. Responsive programming is not necessarily concurrent, but it needs to be considered together when considering concurrency.

 

 

 

[Blogger] Fractured child

Http://www.cnblogs.com/liqingwen/p/7206210.html.

[Reference] Concurrency in C # Cookbook

 

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.