Clumsy threading (was Re: [OT] Corrections about Java)

Jonathan Hogg jonathan at onegoodidea.com
Tue Jul 9 06:22:40 EDT 2002


On 9/7/2002 10:08, in article
mailman.1026205814.27172.python-list at python.org, "Gerhard Häring"
<gerhard.haering at gmx.de> wrote:

> The difference is that Java has some support in the language (only the
> "synchronized" keyword, AFAIK) that supports synchronized methods and
> objects. Python's higher-level threading module was modelled after
> Java's and has everything Java has. It even has Queue.Queue, which Java
> hasn't. Python's features for thread synchronization also appear a lot
> more flexible than Java's to me.

Gah! It always annoyed me immensely that after decades of multi-threading
research the best model Sun could come up with for Java was Monitors
(synchronised methods). Seems Hoare and Dijkstra wasted their time...

On a related note I've been playing with adding guarded methods to Python.
Here's what my guarded version of a queue looks like:

>>> class queue( object ):
... 
...     def __init__( self, max=sys.maxint ):
...         self._max = max
...         self._items = []
... 
...     def _put( self, item ):
...         self._items.insert( 0, item )
...     def _put_guard( self ):
...         return len(self._items) < self.max
...     put = guardedmethod( _put, _put_guard )
... 
...     def _get( self ):
...         return self._items.pop()
...     def _get_guard( self ):
...         return len(self._items) > 0
...     get = guardedmethod( _get, _get_guard )
... 

The basic idea with 'guardedmethod's is that if the guard evaluates to false
then the method will block until the guard is true.

-Ada's-select-coming-next-<wink>-ly y'rs,

Jonathan




More information about the Python-list mailing list