> >How does python handle MT?
>
> Honestly? Really, really badly, at least from a performance point of view.
> There's a single global lock and anything that might affect shared state
> anywhere grabs it.

Python uses global lock for multi-threading. It is reasonable for io thread,
which blocks most of time. It will completely useless for CPU intensive
programs or large SMP machines.

If Perl needs to have full multi-threading, we should better reference to
Java.
Java has the best language/runtime support for MT. It can run thousands of 
threads inside one VM on big SMP machine.

However, Java has made many mistakes with threading. One of it is the
synchronization overhead. A normal Java program can issue one million locks
per second. The JDK 1.0.0 spent 20-25% of time in locking code when run
HotJava. The main problem came from the fact the core library (Vector, 
Hashtable, IO streams, awt etc) are fully synchronized, even though most
of time you don't need them to be synced.

The same story may happen to Perl. If Perl make all operations on SV, AV,
HV sync, the performance will be pathetic. Many SMP machines can only
perform about 10M sync operations per second, because sync op requires 
system-wide bus lock or global memory transaction. This situation will
not change much in the future.

One way to reduce sync overhead is to make more operation atomic instead
of of sync. For example, read() write() are atomic. There is no need to
sync stream. The array get/put are atomic in Java, so we don't need sync
either. The high level library or app itself will be responsible for the
sync.

Hong

Reply via email to