Thread Safety

"Martin v. Löwis" martin at v.loewis.de
Thu Oct 2 16:11:15 EDT 2003


MetalOne wrote:
> Are atomic operations thread safe in Python?  

I don't understand the question. Atomic operations, by nature, can
either completely succeed or completely fail - otherwise it would not
be atomic. This is independent of Python.

In general, you cannot cause inconsistency of Python's internal
representation of objects by pure Python code executed in multiple
threads, so Python itself is thread-safe.

> Can immutable objects,
> such as, strings, be created on one thread and then accessed by
> another thread, without using locks?

Yes.

> Such operations are not guaranteed thread safe in Java due to caching
> optimizations.

But then, in Java, strings are not immutable, no?

Regards,
Martin





More information about the Python-list mailing list