Тёмный

Singleton Design Pattern with thread safety in C++ 

E-GRASP
Подписаться 1,2 тыс.
Просмотров 8 тыс.
50% 1

- 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++

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@mizel_1121
@mizel_1121 Год назад
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
@e-grasp Год назад
Thanks for your comments and you made my day. If you like the video please share and subscribe. Gonna continue
@mizel_1121
@mizel_1121 Год назад
@@e-grasp should u make more videos about design patterns u explain it nicely and I like it
@e-grasp
@e-grasp Год назад
@@mizel_1121 for sure I gonna do it.
@tyferguson5880
@tyferguson5880 10 месяцев назад
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!
@NotMarkKnopfler
@NotMarkKnopfler Год назад
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
@e-grasp Год назад
Thank you very much for your comments, it made my day and give motivation to do much more videos ❤
@chankayau
@chankayau 2 месяца назад
thanks. just to add that i assume here, we are saying that only the CREATION of the static singleton is threadsafe. However, once you have got the reference of the Singleton, you still need to consider the thread-safety on the operation on this object.
@e-grasp
@e-grasp Месяц назад
Yes exact
@pratikshar1662
@pratikshar1662 5 месяцев назад
What an explanation!! Thank you so much!! When can we expect more design patterns videos??
@e-grasp
@e-grasp 5 месяцев назад
Thanks
@niranjanamurthy4168
@niranjanamurthy4168 3 месяца назад
Thank you for this.
@pankajkushwaha3793
@pankajkushwaha3793 Год назад
Very well explain, you have to make copy contructor , assignment operator private also.
@rautyrauty
@rautyrauty Год назад
Thank you! Very good video! 👍
@e-grasp
@e-grasp Год назад
Kindly subs if you like
@Nick-zr2yo
@Nick-zr2yo 10 месяцев назад
Nicely done
@chandusrinivas7813
@chandusrinivas7813 5 месяцев назад
Thank you
@dhinagaranebi9097
@dhinagaranebi9097 Год назад
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
@e-grasp Год назад
As usual, just use the reference variable and access it. No need to be static member always. Obj& ref = Obj::getInstance(); ref.setHeight(100);
@venkateshpalanivel6346
@venkateshpalanivel6346 2 года назад
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
@e-grasp 2 года назад
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
@yudaegam
@yudaegam 2 года назад
thank you, I love you.
@e-grasp
@e-grasp 2 года назад
You're welcome!
@rohitjmics37
@rohitjmics37 2 месяца назад
1 #include 2 3 using namespace std; 4 5 class Singleton{ 6 private: 7 Singleton(){ 8 std::cout
@rohitjmics37
@rohitjmics37 2 месяца назад
I think found the issue in line#25
@amortalbeing
@amortalbeing 5 месяцев назад
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!
@matiascartro9554
@matiascartro9554 3 месяца назад
Thank you for this.
Далее
Thread is not a thread in C/C++ (Linux)
17:03
SINGLETONS in C++
19:16
Просмотров 200 тыс.
MINECRAFT CREPPER EXPLODES SHARK PUPPET!
00:15
Просмотров 6 млн
Doors Harpy Hare (Doors 2 Animation)
00:16
Просмотров 569 тыс.
8 Design Patterns EVERY Developer Should Know
9:47
Master Multithreading : Thread Pool In C++
20:19
Просмотров 10 тыс.
Coding Was HARD Until I Learned These 5 Things...
8:34
Singleton Design Pattern In C++
24:09
Просмотров 79 тыс.
Weak Pointers in C++ (std::weak_ptr)
17:25
Просмотров 49 тыс.
Back To Basics: C++ Containers
31:41
Просмотров 183 тыс.
MINECRAFT CREPPER EXPLODES SHARK PUPPET!
00:15
Просмотров 6 млн