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

  • Home
  • SEARCH
  • 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 6237025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:57:12+00:00 2026-05-24T10:57:12+00:00

#include MutexCondition.h bool MutexCondition::init(){ printf(MutexCondition::init called\n); pthread_mutex_init(&m_mut, NULL); pthread_cond_init(&m_con, NULL); return true; } bool

  • 0
#include "MutexCondition.h"

bool MutexCondition::init(){
    printf("MutexCondition::init called\n");
    pthread_mutex_init(&m_mut, NULL);
    pthread_cond_init(&m_con, NULL);
    return true;
}

bool MutexCondition::destroy(){
    pthread_mutex_destroy(&m_mut);
    pthread_cond_destroy(&m_con);
    return true;
}

bool MutexCondition::lock(){
    pthread_mutex_lock(&m_mut);
    return true;
}

bool MutexCondition::unLock(){
    pthread_mutex_unlock(&m_mut);
    return true;
}

bool MutexCondition::wait(){
    pthread_cond_wait(&m_con, &m_mut);
    return true;
}

bool MutexCondition::signal(){
    pthread_cond_signal(&m_con);
    return true;
}

I am working on a networking programming and I have this and Sound class which extends MutexCondition

#ifndef SOUND_H_
#define SOUND_H_

#include <list>
#include "SoundMetaData.h"
#include "SoundSignature.h"
#include "../MutexCondition.h"

using namespace std;

class Sound : public MutexCondition{

private:
    SoundMetaData *m_metaData;
    list<SoundSignature*> m_soundSignatureList;

public:
    Sound(SoundMetaData *metaData);
    virtual ~Sound();
    SoundMetaData* getSoundMetaData();
    list<SoundSignature*> getSoundSignatureList();

    bool addApplication(string &application);
    bool removeApplication(string &application);
    void addSoundSignature(SoundSignature* signature);

};

#endif /* SOUND_H_ */

If I run my server on gdb. It blows up on pthread_mutex_lock () from the function getSoundSignatureList.

list<SoundSignature *> Sound::getSoundSignatureList(){
    lock();
    list<SoundSignature*> list(m_soundSignatureList);
    unLock();
    return list;
}

I have a class called Engine and 5 different threads create the Engine class based on the packet type it received. A function in the Engine class calls the getSoundSignatureList class. There is any other place where call the Engine class.

I don’t understand how it could blow up on the pthred_mutex_lock

How do I fix this problems? Thanks for your help

EDIT .h file

#ifndef MUTEXCONDITION_H_
#define MUTEXCONDITION_H_

#include <pthread.h>
#include <stdio.h>

class MutexCondition {

private:
    bool init();
    bool destroy();

protected:

    pthread_mutex_t m_mut;
    pthread_cond_t m_con;

public:
    MutexCondition(){
        init();
    }
    virtual ~MutexCondition(){
        destroy();
    }

    bool lock();
    bool unLock();
    bool wait();
    bool signal();

};
#endif /* MUTEXCONDITION_H_ */
  • 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-24T10:57:13+00:00Added an answer on May 24, 2026 at 10:57 am

    I wonder if your mutex instance is being trashed due to a copy or assignment operation (that you may not even be aware of). Mutexes aren’t copyable – you should make sure the wrapper classes you have for the can’t be copied by making the copy-ctor and operator=() private and unimplemented (or similar technique):

    #ifndef MUTEXCONDITION_H_
    #define MUTEXCONDITION_H_
    
    #include <pthread.h>
    #include <stdio.h>
    
    class MutexCondition {
    
    private:
        bool init();
        bool destroy();
    
        // idiom to prevent copying: don't implement these
        MutexCondition( MutexCondition const&);
        void operator=( MutexCondition const&);
    
    protected:
    
        pthread_mutex_t m_mut;
        pthread_cond_t m_con;
    
    public:
        MutexCondition(){
            init();
        }
        virtual ~MutexCondition(){
            destroy();
        }
    
        bool lock();
        bool unLock();
        bool wait();
        bool signal();
    
    };
    #endif /* MUTEXCONDITION_H_ */
    

    Another note: it seems to me that private inheritance of this class might be more appropriate than public inheritance.

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

Sidebar

Related Questions

#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
#include iostream #include vector class ABC { private: bool m_b; public: ABC() : m_b(false)
#include <functional> struct A { int func(int x, int y) { return x+y; }
#include <functional> int func(int x, int y) { return x + y; } int
#include<stdio.h> #include<conio.h> #define SQUARE(x) (x*x) void main() { clrscr(); int i=3,j,k; j=SQUARE(i++); k=SQUARE(++i); printf(\n%d\n%d\n%d,j,k,i);
#include QtGui #include QtNetwork/QtNetwork #include QtNetwork/qnetworkaccessmanager.h #include QtNetwork/qnetworkrequest.h #include QtNetwork/QNetworkAccessManager #include QtNetwork/QNetworkRequest ...... bool
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <iostream> using namespace std; int main() { double u = 0; double w
include(conn.php); $result = mysql_query(SELECT * FROM sggame); while($row = mysql_fetch_assoc($result)); { $id = $row['id'];
#include<iostream> using namespace std; class A { int a; int b; public: void eat()

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.