Why not easy Thread synchronization?

Changjune Kim juneaftn at REMOVETHIShanmail.net
Thu May 15 02:26:48 EDT 2003


"Alex Martelli" <aleax at aleax.it> wrote in message
news:scowa.168135$K35.3951571 at news2.tin.it...
> Iwan van der Kleyn wrote:
>
> > It's very easy writing simple  threaded programs in Python. In fact,
its
> > part of my "evangelize demo's" :-)
> > However, thread synchroni(s/z)ation seems to be a bit more fussy and
> > complex then,  for example, Java.
> >
> > Why not a "synchronization" reserved word like in Java which takes care
> > of "scary" bits under the hood?
> >
> > For example:
> >
> > sync def log(s):  #in which the hypothetical keyword 'sync' makes the
> > function 'log' thread safe
> > sys.stout.write(s)
> > sys.stout.flush()
> >
> > Seems to be a bit more fitting to Python mucking about with locks and
> > mutexes.
>
> The most productive pythonic approach is generally to use Queue instances
> for all inter-thread operation.  A 'sync' keyword would make it harder
> for people to see that.
>
[snip]

I concur with Alex. Queue is a more abstract structure like while-loop as
compared to gotoes.

Have a look at C.A.R. Hoare's CSP. It has been opened public just recently
on the internet. http://www.usingcsp.com/ Highly recommended. It will make
you dislike java's way of concurrency.

To taste CSP in python environment, try stackless python. In java
environment, try JCSP library.

June









More information about the Python-list mailing list