Previous | Next --- Slide 32 of 66
Back to Lecture Thumbnails
mpcomplete

When we use the atomic construct does it matter how long the code is inside the construct? Or is it generally recommended to not have a lot of code in it?

ferozenaina

Aren't atomic constructs typically for a single read/write operation and not for a block of code?

If they can be used for blocks, why not just use atomic over locks everywhere?

bpr

In this lecture, we are working with a "system" that supports declarative semantics. As such, the programmer is declaring to the runtime / compiler that this block of execution should be atomic. Then the system may decide to use locks, transactional memory, etc.

These semantics are different from the implementation which might use atomic_fetch_and_op style operations. And the semantics for this theoretical system may or may not limit the size of a single atomic block. In general, the smaller the block of atomic execution, the better.