I have to design an app that reads UDP data off the local net and stores the data in a Current Value Table (CVT).
Then, a separate thread will come along and read the values out of the CVT, massage them, and send them out over UDP. CVT entries will consist of individual scalars like floats and ints.
My question is, how much mutual exclusion do I need to protect updating/reading from the CVT?
Put another way, if I have a thread writing to an 32bit int and another thread reading from that int, do I need to employ a mutex for it?
I don’t care if the reader thread doesn’t get the absolute latest value stored, I’m just concerned about trying to read that location WHILE it is being changed. I know the keyword “volatile” has uses for this scenario in Java, but it doesn’t do the same thing in C++.
A lot here depends on what sort of platform you’re using to support the threading. If you have atomic types available, you can just use those. Otherwise, yes, you’re pretty much stuck with a mutex (of some sort — many platforms have more than one type).