C # thread synchronization method summary,
During programming, we sometimes use multiple threads to solve the problem. For example, your program needs to process a lot of data in the background, but also make the user interface operational; or your program needs to access some external resources, such as databases or network files. In these cases, you can create a sub-thread for processing. However, multithreading inevitably brings about a problem, that is, thread synchronization. If the problem is not well handled, we will get some unexpected results.
I have read some articles on thread synchronization on the Internet. In fact, there are several methods for thread synchronization. Below I will simply summarize them.
I. volatile keywords
Volatile is the simplest synchronization method. Of course, it is easy to pay. It can only perform synchronization at the variable level. volatile means to tell the processor not to put me into the working memory. Please operate on me directly in the main memory. (【