Thread variables in the thread pool
Do the background development, should all know thread variable this thing, can guarantee each thread to get the data and other threads, as long as do simple set/get operation, can.
-This is the premise-
Today do development, need to pass data to the outer layer in the inner function, a copy is, layer return, this method can be implemented, but I call the three layer method, means that at least change around, more changes mean more bugs, and then think of a magic thread variable can be used.
Code a change, on-line, waiting for the effect, found that the data set in the thread variable number of many times, expect only a few occurrences, and then check and check again, found that the code is not a problem, the operation is normal.
After one hours, it occurred to me that the reason for the thread pool was not really creating a new thread, that is, the contents of the thread variable that were stored in the threads.
With the idea, first search, then test, sure enough, thread pool due to not create a new thread, causing the threading variable is also the previous content, with the conclusion that the modification is very simple, one directly into the thread when set to NULL, the other is to empty after use, the two copy effect is the same. The only difference is whether the following code continues to use this value.