A little understanding of Linux's conduct and threading __linux

Source: Internet
Author: User

1. The overall difference:

A process is the basic unit that serves and allocates system resources, and threads are the basic units of tasks executing, smaller than processes.

Threads can be understood as lightweight processes, which means that threads and processes have similar running structures, such as their own stack space and their own variables. It also means that the thread is running at a smaller cost than the process.

The process has a separate address space, and the thread does not have a separate address space, and it shares the address space with the thread that is in the same process as it.

2. Some problems arising from the distinction

Advantages of Threads:

A, the generation of a thread overhead, do not need to be like the process of code snippets, data segments, stack segments, environment variables and so on, so many resources maintenance costs. At the same time, the switch on the thread is much more efficient than the process. Therefore, in the multitasking high frequency communication scene, many processes show a relatively large advantage.

b, because of the public address space, the communication between threads is not as cumbersome as interprocess communication and much more efficient.

C, through multithreading to achieve multitasking, can optimize the structure of the code, easy to understand the program.

Disadvantages of Threads:

A, multithreaded programs are less robust than multi-process programs because, as long as one thread hangs in a multithreaded program, the entire process is killed.

B, multithreading resources to operate when the need to be very careful to prevent the simultaneous operation of multithreading, where the need to lock, the use of locks need to be very careful, attention to lock the order, to avoid the occurrence of deadlock.

Thought so much for the moment.

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.