I have a performance-sensitive thread1, that does actionA, and another thread that decides for thread1 to do actionB:
<code>std::atomic_bool doActionB = false;
Thread1 func()
{
while (not doActionB.load(std::memory_order_relaxed))
actionA();
while (1)
actionB();
}
Thread2 func2()
{
while (1)
if (condition)
doActionB.store(true, std::memory_order_relaxed);
}
</code>
<code>std::atomic_bool doActionB = false;
Thread1 func()
{
while (not doActionB.load(std::memory_order_relaxed))
actionA();
while (1)
actionB();
}
Thread2 func2()
{
while (1)
if (condition)
doActionB.store(true, std::memory_order_relaxed);
}
</code>
std::atomic_bool doActionB = false;
Thread1 func()
{
while (not doActionB.load(std::memory_order_relaxed))
actionA();
while (1)
actionB();
}
Thread2 func2()
{
while (1)
if (condition)
doActionB.store(true, std::memory_order_relaxed);
}
- Is it guaranteed that Thread1 will be signaled and move to ActionB, at some time?
- Is there a better design for this?