O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding a race condition

The 9.01_race_condition.py code demonstrates a race condition. The program is as follows:

import threadingclass RaceConditionDemo:  def __init__(self):    self.shared_var = 0    self.total_count = 100000    self.demo_of_race_condition()  def increment(self):    for i in range(self.total_count):      self.shared_var += 1  def decrement(self):    for i in range(self.total_count):      self.shared_var -= 1  def demo_of_race_condition(self):    t1 = threading.Thread(target=self.increment)    t2 = threading.Thread(target=self.decrement)    t1.start()    t2.start()    t1.join()    t2.join()    print("value of shared_var after all increments & decrements :", self.shared_var)if __name__ == "__main__":  for i in range(100):     RaceConditionDemo()

The preceding code consists ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required