Alex Rivera | Logout

Volatile equivalent in VB.NET

Asked 2009-07-08T01:04:49.480
15

Possible Duplicate:
How do I specify the equivalent of volatile in VB.net?

What is the VB.NET keyword equivalent of C# "volatile"?

If there is no keyword what mechanism is the equivalent?

Edit
Report

1 Answer

16

There is no equivelent to C#'s volatile keywword in VB.NET. Volatile in C# just makes sure the compiler handles things differently when generating the IL, but the VB.NET compiler does not have this option.

You can work around it this way (taken from this blog post):

Function VolatileRead(Of T)(ByRef Address As T) As T
    VolatileRead = Address
    Threading.Thread.MemoryBarrier()
End Function

Sub VolatileWrite(Of T)(ByRef Address As T, ByVal Value As T)
    Threading.Thread.MemoryBarrier()
    Address = Value
End Sub
answered 2009-07-08T01:09:18.620

Your Answer