Is there a difference between these two code segments:
void f() {
thread_local vector<int> V;
V.clear();
... // use V as a temporary variable
}
and
void f() {
static thread_local vector<int> V;
V.clear();
... // use V as a temporary variable
}
Backstory: originally I had a STATIC vector V (for holding some intermediate values, it gets cleared every time I enter the function) and a single-threaded program. I want to turn the program into a multithreading one, so somehow I have to get rid of this static modifier. My idea is to turn every static into thread_local and not worry about anything else? Can this approach backfire?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…