Git Product home page Git Product logo

bardiparsi / singleton Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 29 KB

This repository contains an implementation of the Singleton Lazy Initialization design pattern in C++20. The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.

License: GNU General Public License v3.0

C++ 100.00%
cpp concurrency concurrent-programming lazy-initialization lazyinitializationexception multi-thread multi-threaded multi-threading multi-threads multiprocessing multithreaded multithreading object-oriented-programming parallel-computing parallel-programming singleton singleton-pattern cpp17 cpp20 lazy-init

singleton's Introduction

Singleton Pattern with Lazy Initialization in C++

This project demonstrates the implementation of the Singleton design pattern with lazy initialization in C++. The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.

Features

  • Lazy Initialization: The Singleton instance is created only when it is first requested.
  • Thread Safety: The implementation is thread-safe to guarantee correct behavior in multi-threaded environments.
  • Expensive Task Simulation: Includes a method expensiveTask() to simulate an expensive operation, showcasing real-world usage scenarios.
  • Error Handling: Proper error handling is implemented to handle invalid arguments and other exceptional situations.

Requirements

  • This project requires C++20 to compile and run successfully.

Compilers

This project is tested and compatible with the following compilers:

  • Mingw g++
  • Microsoft Visual C++ (MSVC)

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details. Feel free to use this content directly in your README.md file on GitHub. Author: Bardi (Masoud) Parsi Contact: [email protected]

Usage

To use the Singleton pattern in your project, follow these steps:

  1. Include the SingleTon.h header file in your project.
  2. Use the getInstance() method to obtain the Singleton instance.
  3. Call the desired methods or perform operations on the Singleton object.
#include "SingleTon.h"

int main() {
    // Obtain the Singleton instance
    SingleTon* singleton = SingleTon::getInstance();

    // Use the Singleton instance
    singleton->expensiveTask(42);

    return 0;
}

singleton's People

Contributors

bardiparsi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.