semaphores and Rlocks

Jive Dadson jsdfaljksdfajil at dfassdfasdfa.invalid
Sat Dec 21 21:34:50 EST 2002


"Martin v. Löwis" wrote:
> 
> Jive Dadson <sdfadfsa at sdfasdfasdfa.invalid> writes:
> [...]
> > Portable to me means portable to at least Win32 and Unix/Linux/POSIX
> > machines, using no C extension modules other than ones that come
> > with the official Python distribution.
> 
> Ok, then no portable solution is possible, since the exposed API does
> not support timeouts.

I didn't make myself clear.  I know the current Python API has minimal
support for timeouts.  Time.sleep() is the only thing I've found.

> 
> However, it is worse: If you were willing to define portable as "at
> least Win32 and Unix/Linux/POSIX machines, including changes to C
> extension modules that come with Python", it still would not be
> implementable. Blocking on a lock is implemented with sem_wait(3) on
> Unix/Linux/POSIX, and that does not support timeouts.

Well, you'd have to implement it differently.  Posix has condition
variables with timeouts in p_threads, for example.  When I programmed
for Unix, I never had trouble finding the OS primitives I needed. 
Admittedly, that was a while back.

> [...]
>
> The threading API is supported in the following variations:
> 
> thread_atheos.h
> thread_beos.h
> thread_cthread.h
> thread_lwp.h
> thread_nt.h
> thread_os2.h
> thread_pth.h
> thread_pthread.h
> thread_sgi.h
> thread_solaris.h
> thread_wince.h
> 
> Finding something that works on all these systems is really tricky.

Yeah, that's quite a list.  Rounding up all the info (or experts) would
be a daunting task - far too involved for me to undertake right now.  Oh
well.

I think I'll just code up a pure Python version of Condition that moves
the latency from the waiting thread into a wakeup service thread.  When
the user thread gets awakened because of a Condition notification, the
latency would be minimal.  When it gets awakened because of a timeout,
the latency could be up to, say, 5 or 10 milliseconds or whatever.  I
seldom care about precise timeouts except maybe in a hard realtime
layer, which is an entirely different world the Land O' Python.  At
higher levels, I generally use timeouts just to be able to recover
leisurely if something that should respond doesn't.

By the way, I posted a question about an IDE that can deal with threaded
programs, and so far no one has responded.  What do you use for
developing threaded programs?  Do you know why IDLE sometimes hangs?

Jive



More information about the Python-list mailing list