368 reputation
28
bio website
location Munich, Germany
age 28
visits member for 1 year, 9 months
seen Sep 9 at 8:17

Programmer at Realmforge Studios mostly doing engine and graphics programming.


Dec
13
comment Command Line Tool to generate a method usage report
Google is a tool you can find tools with :-)
Dec
10
comment Difference between Atomic Operation and Thread Safety?
x=5 is atomic in c#. But immediately after this operation it could be overwritten. x=x+1 is executed by 1. loading x into register 2. increment x in register 3. store x into memory. If a second thread does the same thing at the same time, both will load the same value, increment it and store it resulting in x only getting incremented once instead of twice. InterlockedIncrement either uses a special processor instruction to execute a atomic increment or ensures this by using a locking mechanism, eg CAS, to ensure that while the new value is not written no other thread may read the old value.
Dec
10
comment Difference between Atomic Operation and Thread Safety?
@user960567 the InterlockedIncrement allows incrementing an integer in memory, doing this without a special construct would not work. In C# setting eg x=x+1 is not atomic, only the read and write are which would lead to an increment not getting executed when two threads do it at the same time. Another interesting construct is compare and swap (CAS) which allows you to sync multiple threads because they can detect when another thread as changed the value since it was last read by the current thread and react to it.
Dec
10
comment Difference between Atomic Operation and Thread Safety?
And yes, writing one of these atomic data types in c# is thread safe, but that does not make the function you use them in thread safe. It only ensures that the single write is correctly executed even if a second thread accesses it "at the same time". Never the less, the next read from the current thread is not ensured to get the value previously written as a different thread might have written to it, only that the value read is valid.
Dec
10
comment Difference between Atomic Operation and Thread Safety?
@user960567 please note that that thread only relates to C# which ensures some operations to be atomic by using atomic operations and correct memory alignment internally.
Dec
10
comment Difference between Atomic Operation and Thread Safety?
None of those is ensured to be atomic on all platforms. You can use platform/compiler dependent methods like InterlockedIncrement or the new std::atomic of c++11. Even setting an integer can cause garbage when it is not aligned to the cache lines of your processor as two operations can result in one part getting written from one write and the other part from the other write, at least on PPC.