What is volatile keyword , c# (Csharp) and .NET interview questions ?

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ม.ค. 2025

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

  • @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

  • @rahulmathew8713
    @rahulmathew8713 2 ปีที่แล้ว +1

    Thank you Shiv Prasad sir. Awesome lessons. I learned a lot from you. Your a real guru. Guru that actually imparts knowledge. Big Salute. I cracked many interviews because of your videos. Now I am conducting interviews. Tables turned finally.

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

    I was asked to explain the significance of the term "volatile" at an interview for an internship. Six years later after watching this video I have a better idea of the meaning. Another tricky and not often used term is "extern". Both seem to be great interview questions.

  • @chvsuresh21
    @chvsuresh21 4 ปีที่แล้ว +1

    No words Sir. The best explanation I ever seen.

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

    yes you need to runin full compile mode. It will not work in f5 i.e. debug mode.

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

    Thank you very much, your explanation is very easy, clear and lucid.

  • @marcinszymusiak5422
    @marcinszymusiak5422 4 ปีที่แล้ว +11

    WRONG!!! In you example the COMPILER in Release mode will change "while (o._loop)" to "while (true)" for optimization reason. That why you need VOLATILE! MSDN says: "Fields that are declared volatile are not subject to these optimizations."

  • @onlyforkbj
    @onlyforkbj 13 ปีที่แล้ว +2

    It works as you mentioned when i set the app to "Release" mode and press CTRL + F5.
    But when i just press F5, it does work well without "Volatile" keyword. Any thoughts on this?

    • @xinzhouping
      @xinzhouping 4 ปีที่แล้ว +2

      Because of compiler optimizations for anyone else that is wondering. I know your comment is nine years old.

  • @khunshan
    @khunshan 13 ปีที่แล้ว

    do you have video on how events handling works in .net?

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

    Great video! Keep up the good work my Indian friend! :)

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

    Thank you Sir.

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

    Before scrolling down make sure you put Release instead Debug, it will not work on release even tho few people saying it works without volatile.

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

      Works in release mode as well. Don't see the impact of volatile keyword

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

    You said you will tell us why was the mode set to "Release". Is there a specific reason for this?

    • @georgikaravasilev1653
      @georgikaravasilev1653 7 ปีที่แล้ว +2

      Debug will detect the endless loop and the program will crash

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

    Hello dnfvideo,
    I love your videos and now have a goal of watching them all. I do have a question about volatile. As you mentioned it syncs the local memory (like say the cache on a processor) with the main memory. Do you think it is possible that your code example would ever hit the 3rd console write? In other words, would the local and main memories finally sync up. Of course, this is not the software behavior I would want - it's more of a hypothetical question.
    Thank you,
    Tony

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

    THANK YOU FOR UPLOAD GOOD VIDEO

  • @erikhartmann7517
    @erikhartmann7517 10 ปีที่แล้ว +1

    This works without the volatile keyword using both F5 and Ctrl + F5 on .Net 2.0 and 4.5.

    • @dj78productions
      @dj78productions 10 ปีที่แล้ว +2

      But nobody ensures that there will be a sync between the main memory and thread memory. So it COULD succeed whereas using volotile ensures it WOULD succeed.

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

    thanks a lot

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

    nice explanation sir

  • @SomeRandomDude2007
    @SomeRandomDude2007 8 ปีที่แล้ว +2

    in .Net 4.5 this worked for me without volatile...

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

      Don't use any Console operations inside while .Using Console makes update TSL value.For examle write this inside while:
      while(isTrue)
      {
      bool t = isTrue;
      }

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

    in de loop, use Thread.Sleep(0); and then it's works also without the volatile keyword :-) .
    btw.... you have nice tutorials.

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

      I guess it's because once a thread resumes it creates new local stack and copies values from memory -< same effect as updating.

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

    That is not correct. Volatile stops a current optimization on the compiler. It doesn't really help you "Sync" with memory .... Thats why u see the problem in releaase mode . In release mode compiler does optimizations .Stop teaching people bullshti!

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

    sweet