Introduction to processes and threads

Source: Internet
Author: User

ProgramContains several processes, each of which contains one or more threads that are conceptually known for execution.

A thread is the execution unit of a process. After the process is initialized, the main thread is created. For most applications, only one main thread is required. Even so, the process can also create additional threads.

Each user process has its own private address space, that is, the process has a certain memory area that can be accessed by it. A user process cannot directly access the address space of other processes. There is also a special process, the kernel process, which runs in the superuser permission mode. This process usually includes two threads:

Kernel Server
(Kernel server) thread: an initial process that exists at system startup. It can be executed in heap by the core function request memory allocation or memory redistribution. This is the thread with the highest permissions in the system.

Null
(Empty) thread: when there are no other running threads in the system, this thread starts to run. The null thread makes the processor idle, reducing power consumption.

The thread runs independently and does not know that there are other threads in the process. Thread execution is preemptible. That is to say, the currently running thread may be suspended at any time so that another thread can run.

Priority is set for each thread. At any time, as long as the thread is ready, a thread with a high priority always runs first. If the thread has the same leisurely permission, rotate the scheduling based on the time slice. Context switching includes saving and restoring the thread state. This status not only contains the Processor register (process context), but also contains the address space (process context) that the thread can access ). Process context is switched only when rescheduling is performed between two processes.

Compared with the activity object, the activity object allows non-strong multi-task scheduling in a thread.
A thread can
Suspend, resume, panic and kill another thread.
A thread can be suspended, wake up, throws exceptions, and ends other threads.

After a thread is created, it is suspended. It does not enter the running status immediately until its resume () member function is called.

After a thread is created, it has the default preferred level of eprioritynormal. The thread is initialized and suspended, which means that the running priority of the thread can be changed before the thread starts running (by calling rthread: setpriority ())
.

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.