c++ wati for用法
#include <chrono>
#include <condition_variable>
#include <mutex>
class Logger2 {
std::queue<std::string> shopping_transactionIds;
std::mutex mtx;
std::condition_variable cv;
public:
std::string getShoppingTransactionId() {
std::unique_lock<std::mutex> lock(mtx);
if(!cv.wait_for(lock, std::chrono::seconds(1), [this]{ return !this->shopping_transactionIds.empty(); })) {
LOGW("shopping transaction id is empty");
return "";
}
std::string transactionId = std::move(this->shopping_transactionIds.front());
this->shopping_transactionIds.pop();
return transactionId;
}
// Other class members...
};