Sleep for a short amount of time and look to see if a variable has changed.
#include
#include
#include
std::atomic sharedVar(1);
void sleepy()
{
while (sharedVar.load())
{
usleep(500);
}
}
int main()
{
std :: thread sleepy_thread(sleepy);
// wake up
sharedVar.store(0);
}