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

  • @mizel_1121
    @mizel_112110 ай бұрын

    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

    10 ай бұрын

    Thanks for your comments and you made my day. If you like the video please share and subscribe. Gonna continue

  • @mizel_1121

    @mizel_1121

    10 ай бұрын

    @@e-grasp should u make more videos about design patterns u explain it nicely and I like it

  • @e-grasp

    @e-grasp

    10 ай бұрын

    @@mizel_1121 for sure I gonna do it.

  • @matiascartro9554
    @matiascartro955415 күн бұрын

    Thank you for this.

  • @tyferguson5880
    @tyferguson58807 ай бұрын

    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
    @NotMarkKnopfler9 ай бұрын

    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

    9 ай бұрын

    Thank you very much for your comments, it made my day and give motivation to do much more videos ❤

  • @chandusrinivas7813
    @chandusrinivas78132 ай бұрын

    Thank you

  • @pratikshar1662
    @pratikshar1662Ай бұрын

    What an explanation!! Thank you so much!! When can we expect more design patterns videos??

  • @e-grasp

    @e-grasp

    Ай бұрын

    Thanks

  • @Nick-zr2yo
    @Nick-zr2yo7 ай бұрын

    Nicely done

  • @pankajkushwaha3793
    @pankajkushwaha3793 Жыл бұрын

    Very well explain, you have to make copy contructor , assignment operator private also.

  • @rautyrauty
    @rautyrauty10 ай бұрын

    Thank you! Very good video! 👍

  • @e-grasp

    @e-grasp

    10 ай бұрын

    Kindly subs if you like

  • @yudaegam
    @yudaegam Жыл бұрын

    thank you, I love you.

  • @e-grasp

    @e-grasp

    Жыл бұрын

    You're welcome!

  • @venkateshpalanivel6346
    @venkateshpalanivel6346 Жыл бұрын

    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

    Жыл бұрын

    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

  • @dhinagaranebi9097
    @dhinagaranebi90979 ай бұрын

    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

    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);

  • @amortalbeing
    @amortalbeingАй бұрын

    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!