Critical sections and mutexes

brueckd at tbye.com brueckd at tbye.com
Wed Oct 24 22:56:34 EDT 2001


On Wed, 24 Oct 2001, Cliff Wells wrote:

> > I was merely responding to somebody's not-entirely-true assertion that
> > "_every_ access to that [shared] resource _must_ be enclosed in locks".
>
> My assertion may not have been entirely true, but more useful to someone
> trying to learn threading than a discussion on the esoterics of which Python
> statements may or may not be atomic =)

I do see your point, but I think of it from the opposite point of view: a
newbie learning about threads would be thrilled to get a simple
producer/consumer program working to play around with. Once they see how
cool it is, then you move on to teaching them about locking problems,
mutexes, etc. And hopefully, they played with it enough already to get
bitten by a problem so that they really understand the lesson.

I think it discourages newbies to bombard them with all the locking issues
up front, and it's a real strength of Python (especially for programming
newbies) that you can often "get away" with no explicit thread-safety
measures. Were your first multithreaded programs threadsafe? Mine sure
weren't. But it was okay because at that point it was much more important
to get something working. This is no different than any of the other
newbie-friendly aspects of Python (no type decls, no memory management,
etc.) - people can get up to speed quickly because they do have to get
overwhelmed with the details all at the start.

-Dave





More information about the Python-list mailing list