mercredi 23 mai 2018

Can std::this_thread::sleep_for() be used together with alarm()?

I'm writing unit tests for a program that relies on alarm(2) to implement timeouts with callback handling. In order to make sure various timeouts can occur during tests, I'd like to have the test functions sleep the current thread for a few hundred milliseconds. I looked first at sleep(3), but its docs mention under portability notes that sleep may rely on a SIGALRM signal and therefore should not be mixed with code that uses alarm():

On some systems, sleep() may be implemented using alarm(2) and SIGALRM (POSIX.1 permits this); mixing calls to alarm(2) and sleep() is a bad idea.

Can std::this_thread::sleep_for() be used safely with alarm() across platforms? If so, how is it implemented? If not, how can I sleep the current thread without interfering with alarms/timers?

If it's relevant, my development/unit testing environment is Ubuntu Linux and my target environment is Android.

Aucun commentaire:

Enregistrer un commentaire