Critical sections and mutexes

dharland dharland at surfanytime.co.uk
Wed Oct 24 15:15:20 EDT 2001


"David Brady" <daves_spam_dodging_account at yahoo.com> wrote in message
news:mailman.1003946245.30925.python-list at python.org...
> > -----Original Message-----
> > From: brueckd at tbye.com [mailto:brueckd at tbye.com]
> > No, "normal" operations on Python objects
> > are atomic as far as threads are concerned.
> [snip]
> Interestingly, in several sets of tests, I discovered
> that print statements aren't entirely atomic; tightly
> threaded code can interrupt a print statement after
> the text, but before the newline has been printed:

This is because what really is atomic in python are not "operations" but
Python bytecode.
And print "Boo!" for example is implemented in at least three bytecodes
(LOAD_FAST, PRINT_ITEM, PRINT_NEWLINE), hence the behavoiur you see with the
newline.






More information about the Python-list mailing list