1.3.4 design concurrent and friendly applications

Source: Internet
Author: User

1.3.4 design concurrent and friendly applications

 

When using traditional command styles to Write multi-threaded applications, we have to deal with two problems:

■ It is difficult to convert the existing sequential code into parallel code, because to explicitly use the thread, you must modify most of the basic code.

■ It is difficult to use the shared status and lock. You must carefully consider how to use locks to avoid contention conditions and deadlocks, leaving enough space for parallel execution.

Function programming gives us the answer:

■ When using the Declarative Programming style, you can introduce parallelism in the existing code. With a few elements, you can combine commands with commands executed in parallel.

■ Because of its immutability, it is impossible to introduce contention conditions. You can write code that does not need to be locked. As long as you see which part of the program is independent, you can immediately change it to a parallel running task.

These two aspects can affect how we design applications, and make full use of multi-core machines by making it easier to write code that runs in parallel. However, writing immutable code is not just about getting merged rows. There is still some tricky work to do, but functional programming can minimize the extra effort spent on parallelization.

It's not over yet. When I start to think in the form of functions, I will find other changes in the design ......

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.