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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:14:51+00:00 2026-06-09T16:14:51+00:00

i am using boost mutex in MessageQueue class as a private member in the

  • 0

i am using boost mutex in MessageQueue class as a private member in the following method

 void MessageQueue::Dequeuee()
    {
Request rq(messageWareHouse.front().reqID,messageWareHouse.front().seq,
                                                        messageWareHouse.front().sMessage);
        while(true)
        {
            boost::unique_lock<boost::mutex> lock(qMutex);
            qCond.wait(lock);

    **reqCollection**.find(messageWareHouse.front().reqID)->second.addSegments(messageWareHouse.front().seq,
                messageWareHouse.front().sMessage );
                    }
    ....

reqCollection is a map

map<size_t, Request> reqCollection;

Inside Request when i try to initialize the mutex i am getting the below error

class Request
{

private:

    size_t RequestID;

public:
    boost::mutex qMutex;
    Request(size_t requestID,size_t seq, std::string sMessage);
    void addSegments(size_t seq, std::string sMessage);

};

as far as i searched this error in google here the solution for the problem is stated as

Place (smart) pointers for the mutex or the class containing the mutex

but does this mean i can only use one mutex variable in my whole project by passing pointers? Why boost is protecting the mutex

the error is

Error 7 error C2248: ‘boost::mutex::mutex’ : cannot access private member declared in class ‘boost::mutex’

  • 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-09T16:14:53+00:00Added an answer on June 9, 2026 at 4:14 pm

    The mutex can’t be copied, it is a system resource, so if you have it in some class which get’s copied, the compiler generated copy constructor is called, the compiler generated copy constructor tries to copy the mutex, but it’s copy constructer is private. hence the error.

    If you wan’t a copy of the resource chances are you’de like a different mutex, so you would need to write you’re own copy constructor. If you wan’t the copied objects to share the mutex you can use shared_ptr.

    Alternatively you might not want to copy the objects at all, then you can use std::map< size_t, std::unique_ptr< Request > > if you don’t have std::unique_ptr use shared_ptr

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

Sidebar

Related Questions

I've been using boost::mutex::scoped_lock in this manner: void ClassName::FunctionName() { { boost::mutex::scoped_lock scopedLock(mutex_); //do
I am not using boost libraries. How can i do this using STL? class
I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I am using boost shared pointers in my program, and I have a class
I'm having a weird problem with a threaded class using Boost::threads. Here is a
Code: #include <iostream> #include stdafx.h #include <boost/thread.hpp> #include <boost/thread/mutex.hpp> using namespace std; boost::mutex mut;
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
I have a problem with the following code: #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <iostream>
I'm doing IPC on Linux using boost::interprocess::shared_memory_object as per the reference (anonymous mutex example).
I'm using an object to start boost thread and it has some public member

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.