Python threading (was: Re: global interpreter lock not working as it should)
Armin Steinhoff
a-steinhoff at web.de
Sun Aug 4 14:40:33 EDT 2002
Paul Rubin <phr-n2002b at NOSPAMnightsong.com> wrote in message news:<7xu1mbj67c.fsf at ruckus.brouhaha.com>...
> a-steinhoff at web.de (Armin Steinhoff) writes:
> > > The interpreter in Python is effectively a critical region of
> > > code. Sections of the interpreter that might block are placed
> > > outside of the region so that other threads can enter it while
> > > that thread is blocked. Similarly, every thread is forced
> > > periodically to leave the region and re-enter it in order to allow
> > > the thread scheduler to re-schedule as necessary (the piece you
> > > posted).
> >
> > IMHO ... there is nothing like a 'thread-scheduler' in the python
> > code. All python threads are scheduled by the OS ... that means
> > there is no code in the python program which can _force_
> > periodically a thread to leave this critical section ( e.g. in the
> > middle of the execution of the 10 byte codes).
>
> I think you're confused about the meaning of "critical section".
No .. I believe you didn't understand what I wrote!
> A critical section is a region of code where thread switching is
> impossible, because the code has a lock set,
No ... a thread which owns a critical section can always be preempted
by a thread with a higher priority :)
> interrupts are masked, or something like that.
Critical sections are most used to protect shared resources.
> When the program leaves the critical section by releasing the lock,
> thread switches become possible.
This is a wrong theory ...
> Just because they're POSSIBLE
> doesn't mean they necessarily HAPPEN. It just means the OS's
> scheduler can decide to switch threads there if it wants to. It might
> not want to.
Interesting :) IMHO, scheduler rules are event (IRQ, timers) and
priority driven ... so there is no room for 'may or may not'
> While in the critical section, the OS doesn't have the
> option of switching. That's the difference.
>
> In Python, the interpreter leaves the critical section (releases the
> GIL) every 10 byte codes. That doesn't mean there has to be a thread
> switch then, but just that there MIGHT be one. Do you understand now?
Try to understand what I wrote ... then please ask again.
Cheers
Armin
More information about the Python-list
mailing list