https://github.com/BardiFarsi/SingleTon
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.
https://github.com/BardiFarsi/SingleTon
concurrency concurrent-programming cpp cpp17 cpp20 lazy-init lazy-initialization lazyinitializationexception multi-thread multi-threaded multi-threading multi-threads multiprocessing multithreaded multithreading object-oriented-programming parallel-computing parallel-programming singleton singleton-pattern
Last synced: about 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/BardiFarsi/SingleTon
- Owner: BardiParsi
- License: gpl-3.0
- Created: 2024-04-11T18:51:58.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-24T02:11:01.000Z (11 months ago)
- Last Synced: 2024-07-24T04:26:24.047Z (11 months ago)
- Topics: concurrency, concurrent-programming, cpp, cpp17, cpp20, lazy-init, lazy-initialization, lazyinitializationexception, multi-thread, multi-threaded, multi-threading, multi-threads, multiprocessing, multithreaded, multithreading, object-oriented-programming, parallel-computing, parallel-programming, singleton, singleton-pattern
- Language: C++
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.```cpp
#include "SingleTon.h"int main() {
// Obtain the Singleton instance
SingleTon* singleton = SingleTon::getInstance();// Use the Singleton instance
singleton->expensiveTask(42);return 0;
}