threads: not locking read-only objects

Christopher T King squirrel at WPI.EDU
Fri Aug 6 15:31:46 EDT 2004


On Sat, 7 Aug 2004, Jon Perez wrote:

> Is it safe to not put a lock on an object if it will always
> be read-only in other threads and will only ever be written to
> in just one and always the same one thread?

Only if the writes are guaranteed to be atomic: if the object is ever 
temporarily left in an inconsistent state by the writer (due to a thread 
switch), the readers will read inconsistent data.  If you are sure this 
can't happen, then yes, doing so is safe.




More information about the Python-list mailing list