Colon class § 2.4: Concurrency Paradigm

Source: Internet
Author: User

The important paradigm of lesson two (4)

2.4 Concurrent paradigm--cooperation and competition

Compete in cooperation--"concurrence"

Keywords: programming paradigm, concurrent programming, threading, process, program, function, logical, Object-type

Absrtact: A brief talk on concurrent programming

? Questions

What are the characteristics of concurrent programming?

What are the benefits of concurrent programming?

What conditions should the reasonable concurrent programming design meet?

: Explain

"Are there other types of programming paradigms?" asked the comma curiously. ”

"Not only there, but also a lot. "The colon drank a mouthful of water, leisurely said," the concurrent programming (concurrent programming) is one of them. ”

Exclamation mark somewhat surprised: "Concurrent programming is also a paradigm?" It seems more like a means of providing operational efficiency. ”

"Grand. "The colon shakes its head," true concurrent programming is by no means simply the calling thread [1]api or using keywords such as synchronized, lock, and so on. From the macroscopic architecture design, to the microscopic data structure, process control and even the algorithm, compared with the usual serial programming can be changed. With the dual promotion of hardware performance and user requirements, concurrent programming has become an unavoidable subject. It is no exaggeration to say that concurrent programming is another ideological and technical revolution following OOP. Just compared to OOP, although the same age, but not enough language support, the standard is not uniform, theoretically imperfect, so the revolution is more destructive and constructive. Now let's look at an example to compare two schemes for boiling water and tea. ”

Say a colon and write on the blackboard--

Plan one: Wash the cup, put the tea, water the kettle, boil the tea.

Plan two: Watering the kettle, while boiling water, wash the cup, put the tea, open the tea.

Quotes: "I remember this as an example of operations research, which is obviously better than plan two." From the programming point of view, the program one is serial programming, program two is concurrent programming--boil the thread and wash the tea cup to put the thread is simultaneous. ”

"What if a scenario is programmed with concurrent programming?" The colon pressed.

Quotation mark one Leng, immediately way: "must wash the cup to put the tea first, wash the cup to put the tea at the same time also can not boil water, as for the tea, even have to wait for the waters to open after." ”

The period understood the meaning of the colon: "That is to say, the concurrent programming does not guarantee the improvement of program performance, but also to work on the design." ”

The question mark continues to delve deeper: "Even so, if the hardware does not support, concurrent programming may not be able to improve efficiency ah." For example, on a single processor host, multiple threads can only be analog, logical parallelism, rather than real physical parallelism. ”

"There is some truth in this remark. "The colon is a limited endorsement," but the designer should be proactive, can not wait until the multiprocessor to think of concurrent programming it? Moreover, there is no multiprocessor, is it possible to use multiple single processor host simultaneous operation? To step back, concurrent programming can also improve performance even in the case of a single processor. The most typical example: When a thread is blocked by waiting for a resource, it can switch to another thread instead of leaving the CPU idle. More importantly, is there no other benefit to concurrent programming besides shortening the running time of the program? For example, to open a Web page, you want to download the browser side of the Web page, or download completed after the display? ”

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.