'Does python need barrier command to do singleton code?

While write a singleton code in C/C++ you need barrier as bellow. Does python have(or need ) this command? why?

volatile T* pInst = 0;

if (pInst == NULL)
{
  lock()
  if (pInst == NULL)
  {
    T* temp = new T;
    barrier;  
    // the barrier prevent the cpu change the execute order 
    // first allocate memory (at this time pInst is not null) then generate T
    pInst = temp; 
  }
  unlock;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source