I am writing a C++ program and am currently having an issue where I need atomics, preferably std::atomic_flag, to have thread safe flags. The issue is that I need multiple different atomic flags and rather than declaring them manually like this:
std::atomic_flag flag1 = ATOMIC_FLAG_INIT;
std::atomic_flag flag2 = ATOMIC_FLAG_INIT;
std::atomic_flag flag3 = ATOMIC_FLAG_INIT;
I want to ideally declare them in an array (which I read online is not possible). The reason I want to store them in a container is that I want to access them using indexes. My different threads are each given an index which tells them which of the atomic_flags is assigned to them. Within the main thread, I can use those indexes to set the flags accordingly.
[EDIT] I have successfully identified all my errors. I kept getting access violation errors and have wrongfully assumed them to be related to the atomic variables stores in an array. It was actually a mistake at how I passed my index to the thread.