mirror of
https://github.com/KjellKod/g3log.git
synced 2025-01-19 00:46:03 +01:00
Avoid premature wakeup from reader thread by doing the notify AFTER the mutex is released
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
This commit is contained in:
parent
63616d2acd
commit
0c1845ee18
@ -35,8 +35,10 @@ public:
|
||||
shared_queue(){}
|
||||
|
||||
void push(T item){
|
||||
std::lock_guard<std::mutex> lock(m_);
|
||||
queue_.push(std::move(item));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_);
|
||||
queue_.push(std::move(item));
|
||||
}
|
||||
data_cond_.notify_one();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user