Critical sections and mutexes

Cliff Wells logiplexsoftware at
Tue Oct 23 23:11:08 CEST 2001

On Tuesday 23 October 2001 13:54, David Brady wrote:
> One question that still has not been answered:
> critical sections.  Can they be implemented, or can I
> only lock other threads out of a given resource?

Reading your original post, I believe you are thinking about this wrong 
(please, no offense).  

>From original post:
"only case I can see this being a problem is when, say,
Thread A locks something in the main thread, starts to
interact with it, is preempted, and then the main
thread gets a timeslice and interacts with the locked
resource--which it views as local and doesn't need to
check for a lock."

If you are going to share a resource among threads, then _every_ access to 
that resource _must_ be enclosed in locks (even if you are only reading from 
the resource).  You suggested that you would need a "critical section" so 
that the main thread would not access the resource if another thread is.  If 
you make your main thread check the lock, this won't happen, end of story.  
It doesn't matter if the resource is local to the main thread.


Cliff Wells
Software Engineer
Logiplex Corporation (
(503) 978-6726 x308
(800) 735-0555 x308

More information about the Python-list mailing list