newbie question on threads

Greg Ewing see_reply_address at something.invalid
Thu Oct 10 17:53:11 EDT 2002


Gonçalo Rodrigues wrote:

> Hi,
> 
> I just started out studying threads and fleshing out my first
> multithreaded app. But there is still one thing that I'm not completely
> sure: If a thread acesses a shared object via a non-altering state
> method, and without locking, is this safe?


In general, no, it's not safe if another thread could be
modifying the object at the same time, because the reading
thread could see it in an inconsistent state.

> Better safe-than-sorry strategy?


Yes, unless you really know what you're doing, it would
be best to always use a lock.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list