}
T getFront() {
// Это операция чтения, поэтому требуется блокировка только для чтения
boost::read_write_mutex::scoped_read_lock.readLock(rwMutex_);
if (list_.empty())
throw "empty!";
return(list_.front());
}
private:
std::list<T> list_;
boost::read_write_mutex rwMutex_;
};
Queue<std::string> queueOfStrings;
void sendSomething() {
std::string s;
for (int i = 0, i < 10; ++i) {
queueOfStrings.enqueue("Cyrus");
}
}
void checkTheFront() {
std::string s;
for (int i=0; i < 10; ++i) {
try {
s = queueOfStrings.getFront();
} catch(...) {}
}
}
int main() {
boost::thread thr1(sendSomething);
boost::thread_group grp;