Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:52:37+00:00 2026-06-05T09:52:37+00:00

I am working on a real-time music application. Working with boost library as a

  • 0

I am working on a real-time music application. Working with boost library as a newbie.
I implemented a Producer/Consumer relationship with a protected SyncronizedQueue, actually I implemented the 18.11 and 18.12 sections of https://www.quantnet.com/cplusplus-multithreading-boost/.
When parsing the midi input I get the following exception:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl
<boost::exception_detail::error_info_injector<boost::lock_error> >'
what():  boost::lock_error

Code for parsing input in producer:

RtMidiIn *midiin = new RtMidiIn();
std::vector<unsigned char> message;
int nBytes, i;
double stamp;
m_queue=queue;        

// Check available ports.
unsigned int nPorts = midiin->getPortCount();
if ( nPorts == 0 ) {
    std::cout << "No ports available!\n";
    goto cleanup;
}

midiin->openPort( 1 );

// Don't ignore sysex, timing, or active sensing messages.
midiin->ignoreTypes( false, false, false );

// Install an interrupt handler function.
done = false;
(void) signal(SIGINT, finish);

// Periodically check input queue.
std::cout << "Reading MIDI from port ... quit with Ctrl-C.\n";
while ( !done ) {
  stamp = midiin->getMessage( &message );
  nBytes = message.size();
  if(nBytes>0){
    if((message.size()!=1)&&((int)message.at(0)!=137)){
            for ( i=0; i<nBytes; i++ )
            std::cout << "Byte " << i << " = " << (int)message[i] << ", ";
            if ( nBytes > 0 )
            std::cout << "stamp = " << stamp << std::endl;
            m_queue->Enqueue("asd");
    }
}
}

it breaks on the first time it encounters:

m_queue->Enqueue("asd");

When trying to execute:

boost::unique_lock<boost::mutex> lock(m_mutex);

Any help appreciated!

EDIT1:

This is the SynchronizedQueue object. The exception is thrown when calling Enqueue().

template <typename T>
class SynchronizedQueue
{
private:
    std::queue<T> m_queue;                      // Use STL queue to store data
    mutable boost::mutex m_mutex;                       // The mutex to synchronise on
    boost::condition_variable m_cond;       // The condition to wait for

public:

    // Add data to the queue and notify others
    void Enqueue(const T& data)
    {
        // Acquire lock on the queue
            boost::unique_lock<boost::mutex> lock(m_mutex);
        // Add the data to the queue
        m_queue.push(data);
            // Notify others that data is ready
        m_cond.notify_one();
        } // Lock is automatically released here

    // Get data from the queue. Wait for data if not available
    T Dequeue()
    {

        // Acquire lock on the queue
        boost::unique_lock<boost::mutex> lock(m_mutex);
        //lock();
        // When there is no data, wait till someone fills it.
        // Lock is automatically released in the wait and obtained 
        // again after the wait
        while (m_queue.size()==0) m_cond.wait(lock);

        // Retrieve the data from the queue
        T result=m_queue.front(); m_queue.pop();
        return result;
    } // Lock is automatically released here
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:52:39+00:00Added an answer on June 5, 2026 at 9:52 am

    most times, when I stumble over such an issue, it’s that the mutex that got locked is already destroyed or wasn’t constructed already. Are you sure, the queue, that you are passing to your parser, is already constructed, when the parser threads starts parsing? Or it might be, that the exit of a loop containing the queue as local variable stopped? Maybe you can do a quick test and add a d’tor to the queue and set a breakpoint there.

    regards
    Torsten

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I am working on real-time application with multiple threads. While I am running
I'm working on a real time application implemented using in a SOA-style (read loosely
I'm working on an application that samples audio and needs to do real time
Working with facebook in Android. Sometimes my application is cashing in real time device
I'm working on a quite big application that is in charge of doing real-time
I am working on a real-time analytics application and am using websockets (through the
I'm working on a real-time game application. Most of it is written in Java,
I am working on a real time audio processing dynamically linked library where I
I'm working on a real-time application (lets call it App1) which is communicating with
I'm working with some real-time drawing on a sizable form. When the user resizes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.