Thread-Safety (thread security) means that the Code still works normally when it is executed by multiple threads at the same time. This is especially true when multiple threads need to access the same shared data space. Only one thread can be satisfied. Multi-threaded execution is in a shared address space, and each thread can access the memory space of other threads. In order to make the program conform to the logic sequence of the predefined execution, the thread security concept is put forward. Code conforming to the thread security standard can be better controlled and predicted, it won't go into the embarrassing situation of bug debugging in the future. In practice, it is difficult to determine that a piece of code is thread-safe, and the opposite policy is often adopted: how can this cause thread insecurity? A common section is listed below. The global variables are accessed or the heap is used (especially when automatic collection is not performed ). Allocate/release globally restricted resources, such as files and sub-processes. Using pointers and other similar indirect access methods. On the other hand, sometimes it can ensure that a piece of code (or function) is thread-safe. If it only uses partial variables in the stack to access only the input parameters (actually in the stack) call only the code (or function) that meets the preceding two conditions is called the "pure" function, and work in closed processing mode. Other such self-closing threads are safe. It is difficult to determine, but a proposition can be completely affirmed (or denied) within a local range.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.