![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||||
| |||||
|
|
When thinking about thread-safety I've been assuming that the following are automatically thread-safe without the need for any explicit locking by the programmer: - Reading a reference value |
|
- Writing a reference value |
|
- Reading/writing built-in simple types sized 32 bits or less (Int32, Boolean etc) |
|
I'm slightly worried that I've never seen these assumptions explicitly confirmed. It's implied in some places - e.g. there's an Interlocked.Read(ref long) but no Interlocked.Read(ref int) - but I was hoping someone could point me to an official guarantee in the docs. |
|
I've also been assuming that static constructors are automatically thread-safe |
#3
| ||||
| ||||
|
|
When thinking about thread-safety I've been assuming that the following are automatically thread-safe without the need for any explicit locking by the programmer: - Reading a reference value This depends on the size of the Reference. |
|
- Reading/writing built-in simple types sized 32 bits or less (Int32, Boolean etc) This depends on the Type. Less == yes |
|
It's implied in some places - e.g. there's an Interlocked.Read(ref long) but no Interlocked.Read(ref int) - but I was hoping someone could point me to an official guarantee in the docs. [Interlocked.Read Method (System.Threading)]http://msdn2.microsoft.com/en-us/library/system.threading.interlocked... |
|
The Runtime garantuees that the static constructor of any Type will only be called once. |
#4
| |||
| |||
|
|
When thinking about thread-safety I've been assuming that the following are automatically thread-safe without the need for any explicit locking by the programmer: - Reading a reference value This depends on the size of the Reference. Reading Word-Sizes (Int32 on x32) are thread-safe, but above not (Int64 on x32). Obviously for 64 bit Platforms, reading Int64 is also threadsafe. |

#5
| |||
| |||
|
|
"Günter Prossliner" <g.prossliner/gmx/at>> wrote: Reading Word-Sizes (Int32 on x32) are thread-safe, but above not (Int64 on x32). Obviously for 64 bit Platforms, reading Int64 is also threadsafe. That depends on what you mean by "thread-safe". They're atomic, but unless you take *some* sort of action, there'll be no guarantee you get the latest value. Personally, I don't count "I'll read a value which was definitely valid at some point, but might be an hour out of date" as thread-safe ![]() |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |