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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:58:12+00:00 2026-05-26T01:58:12+00:00

I am having a small issue that I cannot solve. I am making a

  • 0

I am having a small issue that I cannot solve. I am making a small server to redirect my syslog messages to it. It is very basic, but I would like to know what I did wrong cause I keep have the following error when I call join ():

/boost/path/shared_ptr.hpp:418: T* boost::shared_ptr< <template-parameter-1-1> >::operator->() const [with T = boost::thread]: Assertion `px != 0' failed.

The code will explain more:

class SysLogServer
{
public:

  typedef boost::shared_ptr<boost::thread>  Ptr_thread;

  bool Start ()
  {
    ...
    _thrd = Ptr_thread(new boost::thread (boost::bind(&SysLogServer::run, this)));
    if (!_thrd.get ())
      return ERROR ("Thread couldn't be instanciated.");
    ...
  }

  bool Stop ()
  {
    ...
    _thrd->join ();
    ...
  }

private:

  void run()
  {
    ...
  }

  Ptr_thread _thrd;

};

Thank you very much for your help.

PS: If there is any improvment to be more “thread safe”, tell me cause it really interests me 🙂

Edit:

Thank you for your comments, I think that the shared_ptr is indeed useless there but that it might me useful to inherit the class from boost::enable_shared_from_this to ensure that the class is not freed before the end of the thread, which should not happen.

Start() is of course called before Stop(), I perform a simple check with a state attribute. The run() method is simply accepting connections.

class SysLogServer
{
public:

  bool Start ()
  {
    ...
    _thrd = boost::thread(boost::bind(&SysLogServer::run, this)));
    ...
  }

  bool Stop ()
  {
    ...
    _thrd.join();
    ...
  }

  void run ()
  {
    std::cout << "Start running..." << std::endl; // never printed
    // Create a socket
    // Create a sockaddr_in
    // Bind them together
    while (!_serverStopped && !listen(sockfd, 5)) // on Stop(): _severStopped = true
     {
       // Get socket from accept
       // Print the received data
       // Close the socket given by accept
     }
    // close the first socket
  }

  boost::thread _thrd;
};

It works now. I used the almost same solution before with pointers, without any success and my friend SIGSEGV 🙂

Edit 2:

It didn’t work with pointers cause I was forgetting to check in Stop() that the server has been started. The Start() method fails for another reason.

Thank you for your useful advices

  • 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-05-26T01:58:13+00:00Added an answer on May 26, 2026 at 1:58 am

    The reason for the assertion is not immediately clear from the code that you have presented here, but nonetheless, this code could be improved significantly.

    You appear to be using a shared_ptr, but there does not seem to be any need. Ptr_thread could be changed to just boost::thread. This would lead to simpler, more efficient code with easier to understand object lifetimes.

    The code could then be changed to:

    class SysLogServer
    {
    public:
    
      bool Start ()
      {
          ...
          _thrd = boost::thread(boost::bind(&SysLogServer::run, this)));
          ...
      }
    
      bool Stop ()
      {
          ...
          _thrd.join();
          ...
      }
    
    private:
    
        void run()
        {
            ...
        }
    
        boost::thread _thrd;
    
    };
    

    This code is still incorrect if Stop() is called before Start() has been called, which is the only obvious explanation for your original code failing.

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

Sidebar

Related Questions

I'm having an small issue with SQLXML in SQL Server 2008. Here's my testing
Here's a very small issue that I was unable to figure out. I'm sure
I am having a small issue with setSelect and I cannot figure it out.
I know there are already articles that covered this, but I'm having an issue
I am having a small issue with my main menu padding that I'm hoping
We're having a small issue and could use some help - we have the
I'm having a small issue here: <div id=navbar> <ul id=navtabs class=floatcontainer> <li <?php if
I'm new to LINQ and am having a small issue. I created a DBML
I am having an issue when uploading files to tomcat. It seems that tomcat
I'm having a small issue with a bit of jQuery: function getQuickResults(terms) { var

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.