Previous | Next --- Slide 38 of 48
Back to Lecture Thumbnails
kayvonf

Question: Quick review question. What do a mean by "atomic"?

haoala

An atomic operation or set of instructions is one that is done as a single unit - it can't be interrupted by any concurrent processes. If this set of instructions is atomic, then when T0 performs the first of the three instructions, it will also immediately perform the second and third, and the interleaving of these instructions with T1's is not possible.

taz

The meaning of an atomic operation is related to the scientific concept of an atom, which is the smallest unit into which matter can be divided. Likewise, an atomic operation cannot be divided/interrupted by another operation. In other words, when an atomic operation is performed on a shared variable, no other thread can touch the modification half-complete.

Vincent

Is it possible that there are some other types of interleaving as long as the dependency of those serial atomic instructions remain the same?

kavyon

@Vincent Perhaps in another scenario there is an interleaving between multiple threads where program correctness is maintained, but then those instructions need not be atomic. On this slide, there is no interleaving of the three instructions among different threads such that the result is correct, so that's why the slide says these must be atomic.

boba

An atomic set of instructions cannot be interrupted. It is either executed to completion or not executed at all.

rjvani

How is coherency maintained on a hardware level (i.e. How does this work if there's a shared address between caches used in concurrent read/writes)?

anonymous

Atomic means "all or nothing" of the change to variable diff.

200

Here is a nice blog post about atomic operations in C++. Atomic vs. Non-Atomic Operations

eosofsky

Just to summarize the interleaving shown in the slide- Each thread will have its own set of register values. When the work is interleaved as shown, we see that both threads are attempting to update diff by first grabbing the current value, adding r2, and then storing the value. The problem is that thread 1 grabs the value of diff before thread 0 has stored an updated value. Thus any calculations that thread 1 does with diff will not include the update thread 0 is making. Even though thread 0 stores its updated value to diff, thread 1 comes along and overwrites the value. Thus thread 0's work is lost. It is for this reason that the grab, add, and store must be done atomically.

hpark914

Atomic instructions are used as a form of synchronization to change shared data without using a lock, which allows for better parallelism.