jeudi 2 juillet 2015

C++ What are the differences between std::lock and std::unique_lock?

I came into a situation where I need to lock a resource (a std::queue) between two processing threads.

The first thread needs to push data to std::queue, while the second thread is going to pop that data out of the queue and process it.

I need to make sure both threads will not compete for my std::queue.

As this is my first time using C++ locks, I came into different approaches: std::lock and std::unique_lock, but I don´t know which one to choose...

What is the difference between std::lock and std::unique_lock and how they should be used.

Thanks for helping.

Aucun commentaire:

Enregistrer un commentaire