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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:34+00:00 2026-05-28T04:36:34+00:00

I’m working with libconfig++ and threads for making a small server application. The point

  • 0

I’m working with libconfig++ and threads for making a small server application. The point is, libconfig++ is not thread safe, so my idea is to create another class which acts as a wrapper with a Mutex, something like this:

class app_config {
public:
    app_config();
    /* Here be my problems. */
    void set(); 
    void get();
    virtual ~app_config();

private:
    Config cfg;
    boost::mutex *cfg_mutex;
};

Now, this is all good until I realize that libconfig supports plenty of types for its variables. And thats when our protagonist (me) finds himself in search of any C++ guru with a kind heart willing to show him any way to get this working.

Essentially, the get and set functions would need a std::string or a char* path variable containing the path to the configuration file’s variable (I wouldn’t mind using either) and the return type (or the second argument in the set‘s case) should vary…

As always, any help will be appreciated.

Julian

  • 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-28T04:36:35+00:00Added an answer on May 28, 2026 at 4:36 am

    You could as well use this approach. I think it more difficult to missuse and therefore superior. The Libconfig instance is a private member inside of the wrapper and can’t be accessed without a lock.

    #include <boost/thread/mutex.hpp>
    #include <boost/thread/locks.hpp>
    #include <boost/shared_ptr.hpp>
    
    class Libconfig {
    public:
        int Get(const char*) { return 0; }
    };
    
    class LibConfLock;
    
    class LibconfMultithreadingWrapper {
        friend class LibConfLock;
    public:
        LibconfMultithreadingWrapper()
            :m_Libconfig(new Libconfig())
            ,m_Mutex(new boost::mutex())
        {}
    
    private:
        boost::shared_ptr<Libconfig> m_Libconfig;
        boost::shared_ptr<boost::mutex> m_Mutex;
    };
    
    class LibConfLock  {
    public:
        LibConfLock(const LibconfMultithreadingWrapper& wrapper)
            :m_Libconfig(wrapper.m_Libconfig)
            ,m_Mutex(wrapper.m_Mutex)
            ,m_Lock(new LockType(*m_Mutex))
        {}
        Libconfig& GetLibconf() const { return *m_Libconfig; }
    private:
        typedef boost::lock_guard<boost::mutex> LockType;
        boost::shared_ptr<Libconfig> m_Libconfig;
        boost::shared_ptr<boost::mutex> m_Mutex;
        boost::shared_ptr<LockType> m_Lock;
    };
    
    int main() {
        LibconfMultithreadingWrapper wrapper;
        int i = LibConfLock(wrapper).GetLibconf().Get("hallo");
    
        return i;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.