a questions about thread-safety of boolean variables

Charlie Dickens cdickens123 at gmail.com
Wed Sep 30 10:23:54 CEST 2009

Hi,if I have a class A that contains a boolean variable named x, is it safe
to read and change it from different threads without using locks?
Is it guaranteed that A.x will be always True or False, and not any other
weird value that that causes it to be inconsistent (assuming I only set it
to True or False) ?

I have a = A()
first thread does:
if a.x is True :

2nd thread does:
a.x = False

is it safe?

and what if x was a dict ? especially if the only values that are set in the
dictionary are simple: booleans, integers, floats, strings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090930/10c9c333/attachment.html>

More information about the Python-list mailing list