[issue3155] Python should expose a pthread_cond_timedwait API for threading

Gregory P. Smith report at bugs.python.org
Sat Jun 21 01:23:27 CEST 2008


New submission from Gregory P. Smith <greg at krypto.org>:

Currently the threading module has loops in it such as
threading.Condition.wait's loop that attempts to acquire a lock in
non-blocking mode and if it fails, sleeps for a while and trys again. 
(with exponential backoff of sleep time from 500us to 50ms in the
current implementation).

This is inefficient.

Perhaps pthread_cond_timedwait does the same thing internally in some
implementations but even if so, it will do it a lot more efficiently
than doing it in python.

We should expose a PyThread_acquire_lock API that accepts a timeout and
uses pthread_cond_timedwait (or the equivalent on other OSes) when
available.

caveats?  This may alter behavior with regards to KeyboardInterrupt
exceptions coming in being processed or not depending on the particular
OS timedwait implementation.

----------
components: Interpreter Core
messages: 68484
nosy: gregory.p.smith
priority: normal
severity: normal
status: open
title: Python should expose a pthread_cond_timedwait API for threading
type: feature request

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3155>
_______________________________________


More information about the Python-bugs-list mailing list