Reputation: 439
I've stumbled about this thread: Why is volatile not considered useful in multithreaded C or C++ programming?
and stumbled upon the following in the top voted answer...
However, memory barriers also ensure that all pending reads/writes are executed when the barrier is reached, so it effectively gives us everything we need by itself, making volatile unnecessary. We can just remove the volatile qualifier entirely.
Since C++11, atomic variables (std::atomic) give us all of the relevant guarantees.
I'm working on C++98 capable platform, so what memory barrier was available for C++98? I've tried to use mutex for mbed, but I can't logically determine if a mutex is a sufficient way to protect, for example, both a serial write and read happening in two simultaneous threads, since I don't have enough confidence in regards to thread-safety.
What is an easy way to access a simple shared resource in c++98?
Upvotes: 0
Views: 232
Reputation: 8270
but I can't logically determine if a mutex is a sufficient way to protect, for example, both a serial write and read happening in two simultaneous threads
If the mutex code cannot guarantee that, they it's by definition broken. We would have to see that code to check whether it was properly done.
Upvotes: 1
Reputation: 2145
The C++98 Standard is single threaded (threads do not exist) so none in the standard. You will however have OS/Platform specific memory barriers.
Upvotes: 2