Atomic versus nonatomic

It is important to note that it can be surprising for programmers to learn which operations in Python are atomic and which are not. Some might assume that since simple operations take less bytecode than complex ones, the simpler an operation is, the more likely it is to be innately atomic. However, this is not the case, and the only way to determine with certainty which operations are atomic in nature is to perform further analyses.

According to the documentation of Python 3 (which can be found via this link: docs.python.org/3/faq/library.html#what-kinds-of-global-value-mutation-are-thread-safe), some examples of innately atomic operations include the following:

  • Appending a predefined object to a list
  • Extending a list with another list
  • Fetching an element from a list
  • "Popping" from a list
  • Sorting a list
  • Assigning a variable to another variable
  • Assigning a variable to an attribute of an object
  • Creating a new entry for a dictionary
  • Updating a dictionary with another dictionary

Some operations that are not innately atomic include the following:

  • Incrementing an integer, including using +=
  • Updating an element in a list by referencing another element in that list
  • Updating an entry in a dictionary via referencing another entry in that dictionary
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.198.94