c# (Csharp) and .NET :- Multithreading and thread safe objects.

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • For more such videos visit www.questpond.com
    For more such videos subscribe www.youtube.co...
    See our other Step by Step video series below :-
    Learn C# Step by Step goo.gl/FNlqn3
    Learn Design Pattern Step by Step:- goo.gl/eJdn0m
    Learn Angular tutorial step by step tinyurl.com/yc...
    Learn MVC Core step by step :- tinyurl.com/y9j...
    Learn Azure Step by Step :- tinyurl.com/y6...
    Learn SharePoint Step by Step in 8 hours:- goo.gl/XQKHeP
    Python Tutorial for Beginners:- • Python Tutorial for Be...
    Learn Data Science in 1 hour :- tinyurl.com/y5...
    Learn Power BI Step by Step:- tinyurl.com/y6...
    Learn MSBI Step by Step in 32 hours:- goo.gl/TTpFZN
    Learn SQL Server Step by Step tinyurl.com/ja4...
    Learn Tableau step by step :- tinyurl.com/kh...
    In this video we will try to implement thread safety in c# objects using lock keyword. When we talk about multithreading , concurrency can cause abnormal issues if the object is not thread safe. In this c# video we will first try to understand the concept of thread safety and then we will see how locking helps to implement thread safety.
    We are also distributing a 100 page Ebook ".NET Interview Questions". If you want this ebook please share this video in your facebook/twitter/linkedin account and email us on questpond@questpond.com with the shared link and we will email you the PDF.

ความคิดเห็น • 47

  • @dnfvideo
    @dnfvideo  3 ปีที่แล้ว

    Do not miss our Interview Question video series
    30 Important C# Interview Questions : th-cam.com/video/BKynEBPqiIM/w-d-xo.html
    25 Important ASP.NET Interview Questions : th-cam.com/video/pXmMdmJUC0g/w-d-xo.html
    25 Angular Interview Questions : th-cam.com/video/-jeoyDJDsSM/w-d-xo.html
    5 MSBI Interview Questions : th-cam.com/video/5E815aXAwYQ/w-d-xo.html

  • @sikeeeee
    @sikeeeee 8 ปีที่แล้ว +1

    Your videos are clear and easy to understand. In fact your tutorials including this video helped me pass the technical interviews in one of the biggest investment bank in UK. Thanks a lot.

  • @BinaryReader
    @BinaryReader 10 ปีที่แล้ว +26

    you shouldn't lock with "this", instead, you should lock with a private member object of that class, as the caller of the class should not have access on the object you are using to lock. Just sayin'

    • @santoshKoolkarni
      @santoshKoolkarni 10 ปีที่แล้ว

      True but not always. Sometimes it may make sense to lock with this if the private state you are changing could have such wide implication on whole object that none of the operations can be performed without locking. for example if you are updating account balance in an account object.

    • @BinaryReader
      @BinaryReader 10 ปีที่แล้ว +3

      mutable state changes on a object need locking sure, but even in these instances, you would not lock on 'this'. rather, the caller(s) from the outside would be responsible for locking the account object.
      that "lock" would be shared among multiple concurrent processes to ensure the resource (account) is not contested. locking on 'this' removes control from the caller, and leads to confusion. even if on the outset, it appears you are doing the same work. see....
      see stackoverflow.com/questions/251391/why-is-lockthis-bad
      As a note, i am generally against rampant locking on asynchronous operations, i subscribe the whole 'reactive' approach to software design, and am a big advocate for single threaded asynchronous execution over uncontrolled multi threaded execution. The closest analogy i could draw is possibly the nodejs execution model...tho, see the link below if you are curious about the characteristics of the system i describe.
      en.wikipedia.org/wiki/Reactor_pattern
      cheers.

  • @mr_whyy
    @mr_whyy 2 ปีที่แล้ว

    You explain so well dude !

  • @Bytes-Of-Love
    @Bytes-Of-Love 11 ปีที่แล้ว +1

    Nicely explained. Please post video of Monitor, Mutex & Semaphore.

  • @stillborn007
    @stillborn007 12 ปีที่แล้ว

    Thanks for the vids. They are very useful!
    One thing I noticed, because your mic is a bit cracky in the beginning: I turned on English subtitles and it makes the funniest of sentences based on your narrations! :D

  • @tazonis1992
    @tazonis1992 9 ปีที่แล้ว

    Realy nice video, I have one question for you. In this example you open only two threads if you open multiple treads is there a chance for a deadlock? And if there is how you avoid it? For example if more than two threads want access of Num1 and Num2 to read or to write could resolve to a tread starving for ever?(Maybe not just three threads but more likely 10000 threads doing the same thing.

  • @srinivasGrandhi
    @srinivasGrandhi 12 ปีที่แล้ว

    nice example

  • @CariagaXIII
    @CariagaXIII 9 ปีที่แล้ว

    so the lock acts like a try catch

  • @ranjeetnayak7701
    @ranjeetnayak7701 ปีที่แล้ว

    There are lords of messages showing on windows so that's why we are not able to see the code properly

  • @killaurnext
    @killaurnext 11 ปีที่แล้ว +3

    bro...hold the mic away from your mouth
    good vid overall

  • @vishakhaagrawal1822
    @vishakhaagrawal1822 8 ปีที่แล้ว +4

    It is a great video for learning. i could not find linked video of this one. i would like to learn mutex, monitor and semaphore too..do you have video for that too?

  • @GoodNewsJim
    @GoodNewsJim 2 ปีที่แล้ว

    Young programmers please do not do this!
    Old Programmers know better than not to do this.
    The only way to do multithreaded communication between threads properly with lock variables is to pass buffer string arrays of data between them. If you use lock variables for any other reason, your program will likely halt because two doors happen. One locks a door while it waits for another door to open while the other one locked that door while waiting for the other. If you don't understand what I said, you shouldn't be using locking variables.

  • @osnatniknazar7893
    @osnatniknazar7893 12 ปีที่แล้ว +3

    Very clear, thank you! I can not find the next video about : Monitor, Mutex & Semaphore, can you show me the link??

  • @rajeshsuri7411
    @rajeshsuri7411 11 ปีที่แล้ว +2

    Very nicely explained...Please post video of Monitor, Mutex & Semaphore

  • @Mr__B.
    @Mr__B. 9 ปีที่แล้ว +3

    Very nice! Thanks.
    But where is the continuation?

  • @TheIcecoldorange
    @TheIcecoldorange 4 ปีที่แล้ว

    @3:15 it reads: static Maths objMaths = new Maths();
    How is that possible? Static means stateless...

  • @stillborn007
    @stillborn007 12 ปีที่แล้ว +1

    If a part is locked so that only the current thread can execute, what do other threads do in the meantime?
    Do they wait for the lock to disappear or do they skip over the part or do they skip over the complete loop?
    Thanks!

  • @atozonlineguide9893
    @atozonlineguide9893 5 ปีที่แล้ว

    I want to understand full OOPS concert, can anyone help me

  • @manjeetnandal1
    @manjeetnandal1 5 ปีที่แล้ว

    Certainly you & your teaching pattern both are awesome.
    God bless you

  • @enclavedefa1
    @enclavedefa1 12 ปีที่แล้ว

    dnfvideo I have a Question.
    This is the situation:
    I have Form with code that back's up files showin in a label th files that are being copied, and at the sametime picturebox with a Gif image is being show.
    How can I thread the Picturebox to show the gift mage without it to freeze when big file is being copied?
    Thank you.

  • @WoundedEgo
    @WoundedEgo 12 ปีที่แล้ว +1

    VERY clear, thanks!

  • @toolbox1800
    @toolbox1800 11 ปีที่แล้ว

    He is doing it intentionally as an example to demonstrate how threads can lock objects.

  • @morokinaloulou7264
    @morokinaloulou7264 10 ปีที่แล้ว

    mafgamt takhrya m3aha had lhindi

  • @SuperHddf
    @SuperHddf 12 ปีที่แล้ว

    I hate your mic, thx for the video though

  • @RAVINDERKUMARVILASAG
    @RAVINDERKUMARVILASAG 7 ปีที่แล้ว

    good enough to learn Thread concept

  • @monjuilias67
    @monjuilias67 8 ปีที่แล้ว

    Nice tutorial thanks a lot........

  • @pablogarin
    @pablogarin 8 ปีที่แล้ว

    excuse me, but wouldn't it make more sense to NOT declare the object as static? as per my understanding, both threads are using a static object, thus getting such error when calling because the values are the same across all the program (that's what static means)... Just asking because I noticed it at the very beggining and was wondering about it all along the duration of this video...

    • @dnfvideo
      @dnfvideo  8 ปีที่แล้ว +1

      Hello Pablo,
      The whole point of the video is to demonstrate thread safety so we have created a global object a.k.a static object or else we will never get a thread violation error.

    • @pablogarin
      @pablogarin 8 ปีที่แล้ว

      .NET Interview Preparation videos
      yes, I guessed as much... just wanted to be sure it was the case... TY!!

    • @prince237882
      @prince237882 8 ปีที่แล้ว

      One doubt, the static keyword added to the 'objMaths' instance is only for the purpose that it can be accessed by static main method. The exception will happen, whenever the same Maths object is used by threads, static instance or not. Am I right?

  • @newbietester6321
    @newbietester6321 6 ปีที่แล้ว

    thank you for this best tuto

  • @chrisledochowski8007
    @chrisledochowski8007 12 ปีที่แล้ว

    Control f fi FTW

  • @stuggyg01
    @stuggyg01 12 ปีที่แล้ว

    good example

  • @SteveR-1701
    @SteveR-1701 9 ปีที่แล้ว +2

    Thanks, I'm just getting started with threading and that helped me a lot :)

  • @lolrajan
    @lolrajan 12 ปีที่แล้ว

    thanks !

  • @radnascimento
    @radnascimento 12 ปีที่แล้ว

    Good Work!