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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:21:40+00:00 2026-05-18T20:21:40+00:00

Im getting segmentation fault from pthread_mutex_lock, heres my backtrace: Program received signal SIGSEGV, Segmentation

  • 0

Im getting segmentation fault from pthread_mutex_lock, heres my backtrace:

    Program received signal SIGSEGV, Segmentation fault.
0x00007ffff61b03f0 in pthread_mutex_lock () from /lib/libpthread.so.0
(gdb) bt
#0  0x00007ffff61b03f0 in pthread_mutex_lock () from /lib/libpthread.so.0
#1  0x000000000041141f in boost::asio::detail::posix_mutex::lock (this=0x1)
    at /usr/include/boost/asio/detail/posix_mutex.hpp:71
#2  0x00000000004242ee in boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> >::basic_socket_acceptor(boost::asio::io_service&, boost::asio::ip::basic_endpoint<boost::asio::ip::tcp> const&, bool) ()
#3  0x000000000041c7df in Server (this=0x7fffffffe210) at src/server.cpp:12
#4  0x00000000004280bd in main () at src/main.cpp:21
(gdb) 

my code:

#include "server.h"

#include "client.h"



#include <iostream>

#include <boost/thread.hpp>

#include <boost/bind.hpp>



#include "defines.h"



#include "server.h"
#include "client.h"

#include <iostream>
#include <boost/thread.hpp>
#include <boost/bind.hpp>

#include "defines.h"

Irc::Server::Server()
{
    //
}

Irc::Server::~Server()
{
    m_clients.clear();
}

void Irc::Server::start()
{
    m_acceptor = new boost::asio::ip::tcp::acceptor(io);
}

void Irc::Server::startAccept()
{
    SocketPtr p(new boost::asio::ip::tcp::socket(io));
    boost::asio::ip::tcp::resolver resolver(io);
    boost::asio::ip::tcp::resolver::query query(SERVER_ADDRESS, SERVER_PORT);
    boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
    m_acceptor->open(endpoint.protocol());
    m_acceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
    m_acceptor->bind(endpoint);
    m_acceptor->listen();
    m_acceptor->async_accept(*p,
        boost::bind(&Irc::Server::clientHandler, this, 
        p));
}

void Irc::Server::clientHandler(SocketPtr newSocket)
{
    typedef boost::shared_ptr<boost::thread> ThreadsPool;
    typedef std::vector<ThreadsPool> Threads;
    Threads threads;
    for (int i = 0; i < 2; ++i) {
        ThreadsPool p(new boost::thread(boost::bind(
            &boost::asio::io_service::run, &io)));
        threads.push_back(p);
    }
    for (Threads::iterator it = threads.begin(); it != threads.end(); ++it)
        (*it)->join();

    ClientPtr p(new Client(newSocket));
    m_clients[newSocket] = p;
    SocketPtr new_(new boost::asio::ip::tcp::socket(io));
    m_acceptor->async_accept(*new_,
        boost::bind(&Irc::Server::clientHandler, this, new_));
}


#ifndef SERVER_H
#define SERVER_H

namespace Irc
{
    class Client;
    class Server;
} //namespace Irc

#include <boost/asio.hpp>
#include <map>

typedef boost::shared_ptr<Irc::Client> ClientPtr;
typedef boost::shared_ptr<boost::asio::ip::tcp::socket> SocketPtr;
typedef std::map<SocketPtr, ClientPtr> ClientsMap;

class Irc::Server
{
    public:
        Server();
        ~Server();

        void start();

        void startAccept();

        void clientHandler(SocketPtr);

        ClientsMap::iterator begin() { return m_clients.begin(); }
        ClientsMap::iterator end() { return m_clients.end(); }

    private:
        boost::asio::ip::tcp::acceptor* m_acceptor;
        boost::asio::io_service io;
        ClientsMap m_clients;
};
#endif
  • 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-18T20:21:41+00:00Added an answer on May 18, 2026 at 8:21 pm

    You need to post more code (Server::Server()) and post the files in separate code blocks for readability.

    Try changing io to be a pointer, and explicitly initializing it in your constructor:

    Irc::Server::Server() : io()
    {
        start();
        startAccept();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im getting segmentation fault from pthread_mutex_lock, heres my backtrace: Program received signal SIGSEGV, Segmentation
Can you please tell me what I did wrong? I'm getting SIGSEGV (Segmentation fault)
I've a 'C' program which has encountered a strange problem.. I'm getting segmentation fault
I have a C program below written on UNIX. I am getting segmentation fault.
I'm getting a segmentation fault when I try to do pthread_mutex_lock(&_mutex). This is really
I'm getting a segmentation fault from SDL_BlitSurface in C++. here's the code mainScreen->draw( 0,
I'm keep getting a segmentation fault from where I create thread and declare some
I am getting a segmentation fault in console while running the program i am
I am getting segmentation fault in this code but i cant figure out why.
I'm getting a segmentation fault the first time I call malloc() after I protect

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.