Understanding of threads in operating system knowledge

一个新手
Release: 2023-03-16 18:26:01
Original
1592 people have browsed it

Thread

Thread is also called a mini-process. Threads are lighter than processes and easier to create. Switching is easier. If there are a lot of intensive calculations and IO operations. Having multiple threads allows these activities to overlap.

example. When we use word processing software to process text, there will be multiple threads. A gui interface that interacts with the user. One is to handle automatic backup of files. If it is single threaded. When backing up, keyboard operations are ignored. Not user friendly.

Thread model

The process has a thread of execution, in which there is a program counter, registers, and stack records historical record. Processes are used to bring resources together, and threads are the basic unit of CPU scheduling.

The data on the left is the content in the process, which is shared by all threads, and the data on the right is the content in a single thread, shared with other threads No sharing

When a thread completes its work, exit through (thread_exit)

When another common thread calls (thread_yield), it allows the thread to automatically give up the CPU and let another thread run

POSIX thread

In order to implement portable programs. IEEE has developed standards for threads.

Implement threads in user space. Put the entire thread in user space. The kernel knows nothing.

User-level threads can use users to implement their own scheduling algorithms.

Threads are implemented in the kernel. Use system calls. The thread table is stored in the kernel. The cost of creating and destroying threads in the kernel is very high. So use the flag to make this thread non-runnable.

Hybrid implementation

The kernel identifies kernel threads and schedules them. Some kernel threads are reused by multiple user threads.

The above is the detailed content of Understanding of threads in operating system knowledge. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!