From: Chris Thomas Date: 2002-01-17T06:23:58+09:00 Subject: Re: A few words on threads On 1/16/02 12:09 PM, "Paul Prescod" wrote: >> ... Perl provides an interface to native >> threads, as does Python (although I've heard that Python's >> implementation is fairly crude). > > I agree that Python's implementation is crude in an absolute sense (but > not a relative sense...read on). > > Python's threads are crude because although they are OS scheduled, only > one thread can access the Python internals at a time. This is seldom > (never?) a problem on a mono-processor machine but becomes a big problem > on a multi-processor one. It's a problem on single-processor machines too. If thread A wants resource Z, and thread B wants resource Z, and thread A grabs resource Z before thread B, thread B has to wait until thread A is done with resource Z. You really want to let both threads complete as soon as possible, so you want locks to be as finely-grained as is reasonable, even on single-processor machines. This can make a huge difference in the perceived responsiveness of your user interface. >> P.S. Does anyone here have any theories on /why/ threads >> are still percieved as such an arcane topic in the UNIX and >> scripting language communities? > There is your answer. None of the scripting languages (well, bar Jython > and other JVM-based languages) have ideal threading so scripting > language users are not used to it. > > Why is threading so hard for scripting languages? Well scripting > language implementations obviously have many internal data structures. > If you share these between threads then you have to do locking on them > which slows things down. If you do NOT share these between threads then > you have big problems sharing mutable data between threads. Of the > various language communities I think that the Perl world is working on > this most actively so we should watch them. Also (1) multithreaded code is simply not well understood by most programmers (2) the authors of the scripting languages have probably had other priorities until recently. Chris