I wanted to have some practice with async operations, so my goal is to try write a short program that will read and write into the same array. So let's say it is a int array of a thousand indices.
Can I make a async function to go ahead and write let's say all 1's or some random number into all indices from start to end of the array. Then make another async function to read that array from start to end.
That reading function would check if the index it's going to read is =0, and if it does =0, it'll keep checking until it doesn't equal zero. This way there is no need for mutex or atomic operations.
Is that possible? Thank you!
To me this is the simple way to do it, I saw sources online saying I need a mutex or atomic operations but I as I was writing the program I don't see the sense in having a mutex/atomic stuff and I thought of the aforementioned approach and scrapped that old implementation. I am only having one source/function manipulating the array so I don't think it needs a mutex.
TLDR; Is a mutex or atomic operations needed when there is only one writer and one reader to an array?