Locking and try/finally
Daniel Dittmar
daniel.dittmar at sap.com
Wed Dec 4 05:56:22 EST 2002
Duncan Grisby wrote:
> One way to make this kind of thing cleaner is to make locking part of
> the language syntax. Modula-3, one of the inspirations of Python, did
> things like this... (the syntax is probably wrong, but you get the
> idea)
>
> PROCEDURE critical_function(self: T) =
> BEGIN
> LOCK self.mu DO
> (* Manipulate data... *)
> END;
> END;
>
> The compiler turned such statements into the equivalent acquire /
> release pair using TRY..FINALLY.
If Python had Smalltalk like blocks instead of list comprehension, then one
could write
self.mutex.do ([ ... code running in critical section ...])
And it would be possible to do the same for all ressources that have to be
released in a timely manner.
Daniel
More information about the Python-list
mailing list