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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:26:10+00:00 2026-06-03T07:26:10+00:00

In the following code, I haven’;t used any threads. Will creating multiple instances still

  • 0

In the following code, I haven’;t used any “threads”. Will creating multiple instances still be a problem? If I use threads, then since threads share the address space – the functioning may get currupted.

Of course there isn’t any “need” to create multiple objects, but I do so (the way I have done it here) will that be a problem?

#include <iostream>
using namespace std;

class boiler
    {
        private:
            // Non static variables can't be initialized inside a class.
            bool boilerEmpty;
            bool mixtureBoiled;

        public:
            boiler ()
            {
                boilerEmpty    = true;
                mixtureBoiled = false;
            }
            void fillBoiler() 
            {
                if (boilerEmpty == true)
                {
                    cout << "\nFill boiler.";
                    boilerEmpty = false;
                }
            }

            void boilMixture ()
            {
                if ((boilerEmpty == false) && (mixtureBoiled == false))
                {
                    cout << "\nBoil mixture";
                    mixtureBoiled = true;
                }
            }

            void drainMixture ()
            {
                if ((boilerEmpty == false) && (mixtureBoiled == true))
                {
                    cout << "\nDrain mixture.";
                    boilerEmpty = true;
                }
            }
    };

    int main ()
    {
        boiler b, c;
        b.fillBoiler ();
        b.boilMixture ();
        b.drainMixture ();

        c.fillBoiler ();
        c.boilMixture ();
        c.drainMixture ();
    }
  • 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-03T07:26:12+00:00Added an answer on June 3, 2026 at 7:26 am

    If you only use an instance from one thread, then having many instances will cause you no problems. The only way that you invite inconsistent behaviour is by trying to use one instance in multiple threads.

    If you do use one instance in multiple threads, you will want to investigate using a mutex semaphore to ensure that the instance is being used in only one thread at a time.

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

Sidebar

Related Questions

I have following code in my Application. Comments in my code will specify My
I have the following code. It gives me a problem with free memory, but
I haven't used SQLite before and I am looking if I could use it.
I am wondering if there is any potential security risk from the following code.
I'm using the following code in an ASP.NET page to create a record, then
I'm facing an odd behavior. I use the following code to send an HTTP
I am using the following code but haven't tried it yet: <input type=checkbox id=<bean:write
I'm using the following code in an application of mine, and it's always used
I'm having a problem with __sync_fetch_and_and incorrectly performing. I wrote the following code to
In my app I need to send SMS, so I use the following code

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.