Old boy Education daily-March 23, 2017-What is the difference between multi-threading and multi-process, when is it more appropriate to use threads or processes?

Source: Internet
Author: User

Answer:

Process:

Advantage: Multi-process can simultaneously utilize multiple CPU, able to perform multiple operations simultaneously.

Cons: Consume resources (create a process to re-open memory space).

the process is not as much as possible, the general process number equals the number of CPUs .

Thread:

Benefits: Shared memory, especially for IO Operations (network, disk) when (IO operations are seldom CPU-bound), concurrent operations can be performed using multithreading.

Cons: preemption resources.

The more threads are not the better, the concrete case specific analysis, the switching thread related to the request context switch time consuming.

The minimum unit of execution of a task in a computer: a thread.

IO -intensive (no CPU): Multithreading

compute-intensive (with CPU): Multi-process

    • User's Boutique answer:

The road of Jesus 2017/03/23 10:50:40

Multithreading and multi-process are two distinct concepts. Process is the kernel assigned to an application of the relatively independent address space, with its own stack address, of course, is virtual, which protects the kernel, so that the kernel and application isolation, a specific application between the isolation, of course, they can communicate between, depending on the operating system.

Threading is the focus of our programmers, that is, the implementation of our functionality in specific applications. is divided into the main thread and sub-threads, in Android Development We call the main thread as the UI thread, in Java EE and Windows development is the main function and so on, In this case, what happens in the main thread, what operations are placed in the child threads, roughly, the time-consuming operations and the consumption of resources, which are the memory-occupying operations , are placed in the child threads, and the update UI is placed in the main thread, which is implemented through messaging.

Like querying the database, uploading files on the Internet, the breakpoint continues to upload and download big data files Ah, and so on should be placed in the child thread.

Multi-threaded applications, while improving the CPU utilization, but also bring security problems. Bear paw and fish can not have both, how to deal with the problem of efficiency and safety, is really a test of a programmer's level of practical problems.


This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog.51cto.com/3388056/1914576

Old boy Education daily-March 23, 2017-What is the difference between multi-threading and multi-process, when is it more appropriate to use threads or processes?

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.