The function

  • Processes that can perform multiple tasks, such as running multiple browsers simultaneously on a single computer
  • Threads that can perform multiple tasks, such as multiple page Windows in a browser


Differences in definitions

  • Process: it is the running Process of the Process entity. It is an independent unit of the system for resource allocation and scheduling.
  • Thread thread: the smallest unit that the operating system can schedule operations. It is contained within the process and is the actual operating unit within the process. A thread refers to a single sequential control flow in a process. Multiple threads can be concurrent in a process. Each thread performs different tasks in parallel and shares all resources owned by the process with other threads belonging to the same process.


The difference between

  • A program has at least one process, and a process has at least one thread.
  • A line thread cannot execute independently and must depend on a process
  • Threads have a smaller partition scale than processes (fewer resources than processes), making multithreaded programs more concurrent.
  • The process has an independent memory unit during execution, while multiple threads share the memory, thus greatly improving the efficiency of the program.


The advantages and disadvantages

Advantages of the process:

  • With closure and reproducibility;

  • After the appearance of multi-channel programming, the concurrent execution of programs and resource sharing are realized, and the system efficiency and resource utilization are improved.


Process shortcomings:

It is much faster for an operating system to switch threads than to switch schedulers. Moreover, memory cannot be shared between processes and communication is troublesome.

Threads can easily exchange data because they share process memory space. When creating or undoing a process, the system allocates and reclaims resources for it, resulting in significantly higher overhead than when creating or undoing a thread.

Slow switchover, unshared memory, cumbersome communication, and high overhead.


Advantages of threads:

1) Multiple threads running in a process use the same address space with each other, share most of the data, and take little time to start and switch

2) Convenient communication mechanism between threads. Because threads in the same process share data space, data from one thread can be directly used by other threads, which is not only fast but also convenient;

3) Make multi-CPU systems more efficient. The operating system ensures that different threads run on different cpus when the number of threads does not exceed the number of cpus.

4) Improve the program structure. A long and complex process can be considered divided into several threads, separate or semi-independent running parts, so that the program is easier to understand and modify.


Disadvantages of threads:

  • When scheduling, to save the thread state, frequent scheduling, need to occupy a lot of time;

  • Programming error prone (thread synchronization issues).

Threads and processes have their own advantages and disadvantages: threads share data space and have low execution cost, but are not conducive to resource management and protection; The process is the opposite.


The public,

Create a new folder X

Nature took tens of billions of years to create our real world, while programmers took hundreds of years to create a completely different virtual world. We knock out brick by brick with a keyboard and build everything with our brains. People see 1000 as authority. We defend 1024. We are not keyboard warriors, we are just extraordinary builders of ordinary world.