Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does the C++ thread understand

Shulou Source: shulou.com Published: 2022-06-01 19:48:37 09月30日 Update

This article mainly introduces "how to understand C++ threads". In daily operation, I believe many people have doubts about how to understand C++ threads. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how do C++ threads understand"! Next, please follow the editor to study!

CP.4: think in terms of tasks, not threads

Reason (reason)

Threading is a concept at the implementation level, a way to understand machine action. A task is an application-level concept, and you want it to be executed concurrently with other tasks. The concept of application is easier to understand.

Example (sample)

Void some_fun ()

{

Std::string msg, msg2

Std::thread publisher ([&] {msg = "Hello";}); / / bad: less expressive

/ / and more error-prone

Auto pubtask = std::async ([&] {msg2 = "Hello";}); / / OK

/ /...

Publisher.join ()

}

Note (Note)

Except for async (), the standard library features are low-level, machine-oriented, thread / lock-level. These are necessary as foundations, but we must strive to raise the level of abstraction: for productivity, for reliability, and for performance. This is a topic that has a significant impact on the use of higher-level, more application-oriented libraries (building them on top of the annotation library functionality, if possible).

At this point, the study on "how to understand C++ threads" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Threads caching learning tasks levels applications functions more machines concepts problems help practical important necessary next actions reasons reliability basics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Linux macOS MariaDB