Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding block of elements to the end of std::deque
    text
    copied!<p>I've got a wrapper around a std::deque that I'm using to queue up audio data (coming in blocks via libavcodec, if that matters).</p> <p>This is the function that takes a buffer of 16-bit data and adds it to the deque</p> <pre><code>void AVAudioBuffer::enqueue(int16_t* src, size_t num, double pts) { // Save current size of buffer size_t size = data_buffer_.size(); lock(); data_buffer_.insert(data_buffer_.end(), src, src+num); unlock(); // Push PTS value onto queue if (pts != AV_NOPTS_VALUE) { pts_values_.push_back(pair&lt;int,double&gt;(size, pts)); } } </code></pre> <p>Definitions of lock/unlock:</p> <pre><code>void lock() { SDL_mutexP(mute_access_); } void unlock() { SDL_mutexV(mute_access_); } </code></pre> <p>My problem is, when the data_buffer_.insert statement is included in the code, the thread this function is in will execute once and then lockup. If I remove the code, it works. I tried replace the insert with a manual iteration of the src data, calling push_back() for each element, and this too causes the thread to lock. </p> <p>Is this a valid way to append data to a deque? I tried it in a test program and it seemed to work fine, and the documentation seems to imply that it's OK. Why would this cause my thread to die?</p> <p>Updated info: Added error messages for when locking/unlocking fail, and they both succeed just fine. I instrumented them to verify they're being executed in pairs, and they are. It's got to be something with the deque::insert call that's messing things up, I can remove it and things get moving again. </p> <p>Update: I found the problem, I refactored the code and missed a constant so the dequeue was always checking as full, causing a loop =(</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload