boost::atomic has function store and load. However, there is a function that can return and current value and set the value a same time, which means the two operations are atomic.
Following code is the problem
void Initialize()
{
///if some other thread is initializing, skip this step
if (m_initializing.load(boost::memory_order_relaxed))
return S_FALSE;
m_initializing.store(true, boost::memory_order_relaxed);
return S_OK;
}
If two threads call this initialize function concurrently. thread A and B call load and returns false, they will call store at same time. So I want a atomic function. if A finds m_initializing is false, and set to true at same time. so that thread B knows some thread is working on it.