Sorry if my doubt is too naive. But I have a difficulty in typecasting std::atomic
to char*
type. Is casting from std::atomic to char
is valid?
Can I write to such type casted variable. I am sure that there will be no multithreaded reads/writes while a thread tries to write into the variable.(I understand that, there is no need for using atomics when there will be no concurrent access on this variable)
std::atomic<uint8_t>* data_;
char *data = reinterpret_cast<char*>(data_);
*data |= mask;
Is it safe to do?
EDIT: I am not sure if its worth mentioning. In my code,
char *raw;
// variable raw is allocated
std::atomic<uint8_t>* data_ = reinterpret_cast<std::atomic<uint8_t>*>(raw);
The above is how the std::atomic< uint8_t>
is created (as char and type casted to std::atomic type).
Thanks :)