Home >Backend Development >PHP Tutorial >Understanding of threads in operating system knowledge

Understanding of threads in operating system knowledge

一个新手
一个新手Original
2017-10-23 09:29:241628browse

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!

Statement:
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