Volatile usage

CS0518 Predefined type ‘System.Runtime.CompilerServices.IsVolatile’ is not defined or imported

is it not implemented, a bug or not needed?

What are you trying to do?

From the MS documentation for the method…

The classes in System.Runtime.CompilerServices are for compiler writers’ use only.

C# Reference

“The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times.”

a workaround is the usage of lock but this is not the question

Using a lock or a Mutex is not a workaround… It is the way you control access to a variable between threads.

If you want a precise answer to your original question, then I would say “not needed”.

1 Like

a lock statement would serialize the access by this only one thread per time is able to change the value so it would be a workaround

“would say not needed” does not answer the question as only GHI is able to answer this because it depends on how threads are implemented in TinyCLR

with NETMF everything was volatile and based on how NETMF handled threads not needed as only one thread was active per time thanks to the scheduler

so please could i get an official answer

thank you

MF has a preemptive dispatcher with a 20ms time slice. Locking was needed but not volatile.

1 Like

Your user name can mislead users thinking you are an official employee, plus it is a trademark of ours. Please update your user name.

Most of us use our real names, which we encourage.

i am not talking about NETMF i am talking about TinyCLR
even if TinyCLR is based on NETMF it is different

Mike, thank you for your posts but you are not helpful

Generally speaking, threading and timers are still implemented in TinyCLR just like how they were in NETMF. Similar goes to “volatile”, it is not implemented in either system but there are ways to make your code thread-safe as suggested by @Mike

I hope this helps.

yes, this was helpful
thank you

Sorry I was not helpful. I will no longer try to answer your questions. I apologize for wasting your time.

1 Like