B
B
Boris192018-04-13 16:15:10
Python
Boris19, 2018-04-13 16:15:10

How to figure out which operation is atomic?

For example, the list.append(x) operation is atomic, how can this be understood from the python bytecode?

>>> def k():
...     l = []
...     l.append(10)
...
>>> dis(k)
  2           0 BUILD_LIST               0
              2 STORE_FAST               0 (l)

  3           4 LOAD_FAST                0 (l)
              6 LOAD_ATTR                0 (append)
              8 LOAD_CONST               1 (10)
             10 CALL_FUNCTION            1
             12 POP_TOP
             14 LOAD_CONST               0 (None)
             16 RETURN_VALUE

Here I see 3 instructions here:
4 LOAD_FAST 0 (l)
6 LOAD_ATTR 0 (append)
8 LOAD_CONST 1 (10)
So why is this instruction atomic?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris19, 2018-04-19
@Boris19

In general, I figured it out without the help of the community!
Everything turned out to be simple, the LOAD_FAST, LOAD_ATTR, LOAD_CONST instructions simply load references to the necessary objects and only the CALL_FUNCTION instruction changes the data - therefore the whole operation is atomic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question