is a c++ member array of struct thread safe using only one index per thread ?
using the following class:
typedef struct {
bool bFlag;
unsigned int uiNum;
} TC_MYSTRUCT;
class MyClass {
public:
MyClass();
~MyClass();
int GetFreeIndex();
void SetIndexDataNum(int idx, int num);
int GetIndexDataNum(int idx);
private:
TC_MYSTRUCT m_arr[10];
};
- this class is defined as a global var.
- GetFreeIndex() is synchronized with critical section ...
- there are some threads getting a free index from the member array with GetFreeIndex()
- SetIndexDataNum modifies it's own unique entry within m_arr.
- within a thread SetIndexDataNum/GetIndexDataNum are called only with the thread specific index
- SetIndexDataNum/GetIndexDataNum can be called at the same time, but with different index
- SetIndexDataNum/GetIndexDataNum are never called at the same time within a thread
is it thread safe to use methods SetIndexDataNum/GetIndexDataNum without critical section inside ? (since the are addressing only a specific array index)