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 8209133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:37:00+00:00 2026-06-07T09:37:00+00:00

I have a few singleton classes with some extra functions which are run in

  • 0

I have a few singleton classes with some extra functions which are run in separate thread. The structure looks like:

class Singleton
{
   private:
      boost::mutex mMutex;
      std::vector<std::string> mMessages;

   public:
      void AddMessage(const std::string &msg)
      {
         mMutex.lock();
         mMessages.push_back(msg);
         mMutex.unlock();
      }

      void Sender()
      {
          while (true) {
             mMutex.lock();
             for (size_t i = 0; i < mMessages.size(); ++i)
             {
                 // Do something with mMessages[i]
             }
             mMutex.unlock();
          }
      }
};

...

int main()
{
   Singleton *handle;
   handle = Singleton::instance();
   boost::thread sender(boost::bind(&Singleton::Sender, handle));

   ... app cycle ...
}

Sometimes it fails with error:

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
Aborted

What could it be and what’s the best why to find out the reason of assert?

  • 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-07T09:37:02+00:00Added an answer on June 7, 2026 at 9:37 am

    May be that you did not create the object Singleton! So the mutex is not created either.

    Try:

    int main()
    {
       Singleton handle; //object, not pointer
       boost::thread sender(boost::bind(&Singleton::Sender, &handle));
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume you have a Singleton Constants class, instance of which you'd like to use
We have a lot of class code which has some boilerplate like the following:
I have few graphic effects on image which i am able to run on
I have separate repository classes for each entity. Now I would like to implement
I have a Logger class which is implemented singleton. The class is simple and
I have a few classes, such as those that outline database table structure or
A few questions about Castle Windsor. I have a service that looks like this:
I have few text fields like SSN , phone number and email id. I
I have few pages in following structure. --Project |---WebContect |----Admin/ * |----Author/ * |----Readonly/
We have few components like libraries dlls When initially created I ran the following

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.