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
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.
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.
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."
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?
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
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.
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; }
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!
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
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.
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.
No words Sir. The best explanation I ever seen.
yes you need to runin full compile mode. It will not work in f5 i.e. debug mode.
Thank you very much, your explanation is very easy, clear and lucid.
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."
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?
Because of compiler optimizations for anyone else that is wondering. I know your comment is nine years old.
do you have video on how events handling works in .net?
Great video! Keep up the good work my Indian friend! :)
Thank you Sir.
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.
Works in release mode as well. Don't see the impact of volatile keyword
You said you will tell us why was the mode set to "Release". Is there a specific reason for this?
Debug will detect the endless loop and the program will crash
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
awesome sir
THANK YOU FOR UPLOAD GOOD VIDEO
This works without the volatile keyword using both F5 and Ctrl + F5 on .Net 2.0 and 4.5.
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.
thanks a lot
nice explanation sir
in .Net 4.5 this worked for me without volatile...
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;
}
in de loop, use Thread.Sleep(0); and then it's works also without the volatile keyword :-) .
btw.... you have nice tutorials.
I guess it's because once a thread resumes it creates new local stack and copies values from memory -< same effect as updating.
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!
sweet