Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does threading mean in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "what is the meaning of threads in linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the meaning of threads in linux" this article.

In linux, thread refers to an execution route within a program, that is, a control sequence within a process, and all processes have at least one thread of execution. Threads are the smallest unit of program execution. Threads share process data, but they also have part of their own data.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

The concept of Linux thread

What is a thread?

An execution route in a program is called a thread. A more accurate definition is that a thread is "a control sequence within a process".

All processes have at least one thread of execution.

Processes and threads

Process is the basic unit of resource allocation and competition.

Thread is the smallest unit of program execution.

Threads share process data, but also have part of their own data

Thread ID

A set of registers: IP,PSW, stack pointer

Stack

Errno

Signal state

Priority

The difference between fork and creating a new thread

When a process makes a fork call, a new copy of the process is created, and the new process will have its own variables and its own PID. The run time of this new process is independent, and its execution is almost completely independent of the process that created it.

When you create a new thread within a process, the new executing process has its own stack (and therefore its own local variables), but shares global variables, file descriptors, signal handlers, and current working directory state with its creator.

Advantages of threads

It is much less expensive to create a new thread than to create a new process.

Switching between threads requires much less work from the operating system than switching between processes

Threads consume much less resources than processes

Can make full use of the number of parallelism of multiprocessors

The program can perform other computing tasks while waiting for the end of the slow Istroke O operation.

Compute-intensive applications that decompose computing into multiple threads in order to run on multiprocessor systems

In order to improve the system, the Imax O operation is overlapped in the intensive application. Threads can wait for different IWeiO operations at the same time.

Disadvantages of threads

Performance loss

A compute-intensive thread that is rarely blocked by external events is often unable to share the same processor with other threads. If there are more compute-intensive threads than available processors, there may be a significant performance loss, which refers to the addition of additional synchronization and scheduling overhead while the available resources remain the same.

Reduced robustness

Writing multithreading requires more comprehensive and in-depth consideration, and in a multithreaded program, it is highly likely to be caused by minor deviations in time allocation or by sharing variables that should not be shared. in other words, there is a lack of protection between threads.

Lack of access control

Process is the basic granularity of access control, calling some OS functions in a thread will affect the whole process.

The difficulty of programming is improved

Writing and debugging a multithreaded program is much more difficult than a single-threaded program.

Thread scheduling contention range

The operating system provides various models for scheduling threads created by the application. The main difference in the time of these models is that when competing for system resources (especially CPU time), the thread scheduling contention range (thread-scheduling contention scope) is different.

Process contention scope (Process contention scope): threads compete for "scheduled CPU time" in the same process (but not directly with threads in other processes).

System contention scope (System contention scope): threads compete directly with other threads within the "system scope".

The above is all the content of this article "what is the meaning of threads in linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report