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

preview_player
Показать описание

See our other Step by Step video series below :-

In this video we will try to understand what is the need of volatile keyword in c# Csharp.

Рекомендации по теме
Комментарии
Автор

Do not miss our Interview Question video series

dnfvideo
Автор

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.

rahulmathew
Автор

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.

jaminyah
Автор

No words Sir. The best explanation I ever seen.

chvsuresh
Автор

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."

marcinszymusiak
Автор

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

Islamadem
Автор

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

dnfvideo
Автор

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?

onlyforkbj
Автор

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

MrsNorrisCat
Автор

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

khunshan
Автор

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.

ZnSstr
Автор

I tried it by myself and it worked without the 'volatile' keyword. how come the same code behaves differently? I compiled it as .net 2.0 and 3.5 - same result.

mailjunkil
Автор

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

erikhartmann
Автор

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

SomeRandomDude
Автор

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

sandeshkota
Автор

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

tonybaker
Автор

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

tomdilen
Автор

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!

ivailomanolov