removeall() in list

Paul Rubin http
Fri Jan 11 18:51:16 EST 2008


castironpi at gmail.com writes:
> > 2. Associate a lock with the list.  Anything wanting to access the
> > list should acquire the lock, do its stuff, then release the lock.
> > This gets confusing after a while.
> 
> To keep it generic, how about:
> 
> listA.op( insert, x )
> listA.op( remove, x )

Sure, there are various ways you can make the code look uniform.  What
gets messy is if you want to (say) operate on several lists at the
same time, which means you need to hold multiple locks simultaneously,
and some other thread is also trying to do the same thing.  If you
acquire the locks in the wrong order, you can get a situation where
both threads deadlock forever.




More information about the Python-list mailing list