I want to have a member variable shared inside a thread ,but not shared among threads .
It behaves like a static member but it's only "global" in one thread ,it's a thread local variable .
I can think of two solutions :
First ,create a local variable in each thread ,then pass this variable as an argument to every method that uses it .(which result in coupling)
Or ,define a struct named MyStruct which contains a thread local variable and a thread ID ,then make all these MyStructs a vector ,use this vector as a static member variable .
Every time using this member variable , get thread ID first ,then find the MyStruct which has the same thread ID , if not found ,push back a new MyStruct .Erase this Mystruct before thread ends .(which is inconvenient)
Is there a simple solution ?