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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:27:34+00:00 2026-05-26T00:27:34+00:00

There is some exemplary class of container in pseudo code: class Container { public:

  • 0

There is some exemplary class of container in pseudo code:

class Container
{
public:
  Container(){}
  ~Container(){}
  void add(data new)
  {
    // addition of data
  }
  data get(size_t which)
  {
    // returning some data
  }
  void remove(size_t which)
  {
    // delete specified object
  }

private:
  data d;
};

How this container can be made thread safe? I heard about mutexes – where these mutexes should be placed? Should mutex be static for a class or maybe in global scope? What is good library for this task in C++?

  • 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-26T00:27:35+00:00Added an answer on May 26, 2026 at 12:27 am

    First of all mutexes should not be static for a class as long as you going to use more than one instance. There is many cases where you should or shouldn’t use use them. So without seeing your code it’s hard to say. Just remember, they are used to synchronise access to shared data. So it’s wise to place them inside methods that modify or rely on object’s state. In your case I would use one mutex to protect whole object and lock all three methods. Like:

    class Container
    {
    public:
      Container(){}
      ~Container(){}
      void add(data new)
      {
        lock_guard<Mutex> lock(mutex);
        // addition of data
      }
      data get(size_t which)
      {
        lock_guard<Mutex> lock(mutex);
        // getting copy of value
        // return that value
      }
      void remove(size_t which)
      {
        lock_guard<Mutex> lock(mutex);
        // delete specified object
      }
    
    private:
      data d;
      Mutex mutex;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there some 'where' type contraints in can add to make the follwing code
Is there some efficient way how to get length of data in varbinary(max) filestream
Is there some easy way in linux to listen for data on network and
Is there some way to get chrome to launch my text editor when I
Is there some hidden meaning in this code which I don't see in java?
Is there some way that an Android app written in Air can send data
Is there some sort of Zend code guard for rails applications ? Sultan
Is there some sort of data structure in Java that resembles a HashMap that
There some code in one gstreamer-plugin: static GstFlowReturn gst_ebml_peek_id_full (GstEbmlRead * ebml, guint32 *
Is there some standard email validator code sample for Java ME or BlackBerry?

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.