vendredi 31 juillet 2015

does std::unique_lock::try_lock_until busy wait?

I'm thinking of using

auto now = std::chrono::high_resolution_clock::now();

std::unique_lock<std::mutex> lock(mutex, std::defer_lock);
if(lock.try_lock_until(now + std::chrono::milliseconds(15))
{
    // swap some buffer pointers...
    lock.unlock();
}

However, it's not clear to me from the documentation if try_lock_until is implemented as a busy wait or if the thread will yield /sleep in between tries (my desired behavior). Is this the best way to query a lock while minimizing thread resource usage?

Aucun commentaire:

Enregistrer un commentaire