現在、並行キューを書き込もうとしていますが、自分では説明できないセグメンテーション違反がいくつかあります。私のキューの実装は、基本的に、このサイトの最初のリストによって提供されます。
このサイトには、オブジェクトがキューから並行して削除されると競合状態が発生すると書かれていますが、競合状態が発生する理由がわかりません。誰か説明してもらえますか?
編集:これはコードです:
template<typename Data>
class concurrent_queue
{
private:
std::queue<Data> the_queue;
mutable boost::mutex the_mutex;
public:
void push(const Data& data)
{
boost::mutex::scoped_lock lock(the_mutex);
the_queue.push(data);
}
bool empty() const
{
boost::mutex::scoped_lock lock(the_mutex);
return the_queue.empty();
}
Data& front()
{
boost::mutex::scoped_lock lock(the_mutex);
return the_queue.front();
}
Data const& front() const
{
boost::mutex::scoped_lock lock(the_mutex);
return the_queue.front();
}
void pop()
{
boost::mutex::scoped_lock lock(the_mutex);
the_queue.pop();
}
};