Singleton Design Pattern with thread safety in C++
- How to create a singleton design pattern both in classical C++ and Modern C++
- How to create singleton using pointer and make it thread safe with std::mutex
- How to create singleton using reference and thread safe without even using std::mutex (Meyer's Singleton design pattern)
#cpp #designpatterns #singleton #meyers #meyerssingleton #programming #thread #multithreadingincpp #c++ #linux #gcc #g++
Пікірлер: 22
Why u stop explain design patterns? I think you are best person to explain that u actually did this video very simple to understand please do more videos bro
@e-grasp
10 ай бұрын
Thanks for your comments and you made my day. If you like the video please share and subscribe. Gonna continue
@mizel_1121
10 ай бұрын
@@e-grasp should u make more videos about design patterns u explain it nicely and I like it
@e-grasp
10 ай бұрын
@@mizel_1121 for sure I gonna do it.
Thank you for this.
I don't comment on videos often but this video was extremely helpful man. You delivered the information in a very quick and easy-to-understand way. Would love to see you continue making videos covering more programming concepts! Thank you for this!
This is gold. Your example and narrative are very clear and simple to understand. You are a talented teacher. Thank you for sharing. Regards from the UK 👍
@e-grasp
9 ай бұрын
Thank you very much for your comments, it made my day and give motivation to do much more videos ❤
Thank you
What an explanation!! Thank you so much!! When can we expect more design patterns videos??
@e-grasp
Ай бұрын
Thanks
Nicely done
Very well explain, you have to make copy contructor , assignment operator private also.
Thank you! Very good video! 👍
@e-grasp
10 ай бұрын
Kindly subs if you like
thank you, I love you.
@e-grasp
Жыл бұрын
You're welcome!
One thing that we lose in the modern way is controlling the lifetime of the singleton. Before we had the control to destroy things. One issue with static vars is they will be destroyed when the program goes down. And we need to be careful about what we destroy during that time. Even Microsoft warns about these things. IMHO, Old way is much safer because of lifetime control. And if our program doesn’t call get instance 100’s of times I think performance wouldn’t be too bad. What do you think?
@e-grasp
Жыл бұрын
What I feel is - since singleton means one object through out entire program so destroying the singleton does not make any sense and there is no mere use of object once destroyed - Once program is exiting object is destroying so we no need to take care of anything right. In old way we need to manage thread safe, by default static is thread safe in modern cpp compiler. I feel w.r.t maintaining the code new way is easy Whats your opinion
Hi thanks for this videos , how we can use this as object for example there is an member variable m_height, method setHeight(), how we can call setHeight() here
@e-grasp
9 ай бұрын
As usual, just use the reference variable and access it. No need to be static member always. Obj& ref = Obj::getInstance(); ref.setHeight(100);
for the love of God dont use black and then a white background! that damn thing hurts! also you need to delete the copy and move constructors so someone doesnt create chaos unintentionally!