What is linux coroutine

王林
王林Original
2020-06-29 13:44:373858browse

Linux coroutine is a lightweight user-mode thread, and the operating system is unaware of the coroutine. Coroutines implement collaborative scheduling (non-preemptive scheduling), that is, coroutine switching is controlled by the current coroutine and actively gives up the CPU. Typically, a thread contains multiple coroutines.

What is linux coroutine

Coroutine definition

(Recommended learning: linux tutorial)

Coroutine ), is a lightweight user-mode thread, and the operating system has no awareness of coroutines. What is implemented is collaborative scheduling (non-preemptive scheduling), that is, coroutine switching is controlled by the current coroutine and actively gives up the CPU (for example, when the current coroutine is waiting for asynchronous network IO).

Normally, a thread contains multiple coroutines.

Characteristics of coroutines

1. Coroutines are a concurrently running multi-task system, generally driven by an operating system thread;

2. Coroutine task metadata The resource usage is lower than that of operating system threads, and the task switching overhead is small;

3. Coroutines are collaborative scheduling between tasks, that is, one task actively gives up execution and then schedules another task to run.

The above is the detailed content of What is linux coroutine. 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