[PATCH] libc: make I/O locking cancel-safe with futexes

Rich Felker dalias at aerifal.cx
Fri Sep 28 12:30:18 UTC 2012


On Wed, Sep 12, 2012 at 04:55:29PM +0200, Carmelo AMOROSO wrote:
> From: Filippo ARCIDIACONO <filippo.arcidiacono at st.com>
> 
> Current implementation of I/O locking macros using futexes are not
> cancel safe, as if a thread is cancelled while doing IO operations,
> it does not release the lock on the IO stream. So following
> attempts to acquire the IO stream's lock would dead-lock.
> In order to make it cancel-safe, it needs to rely upon the
> pthread_cleanup push & pop protocol, as it is already done for
> the pthread_mutex counterpart.

This is an unnecessarily heavy approach. Cancellation cannot be acted
upon unless a call to a cancellation point is made, so you do not need
to install cleanup handlers whenever the file is locked, only when
cancellable actions will be performed under lock, i.e. when the buffer
needs to be flushed or filled. Perhaps it matters less with NPTL's
exception-based cancellation, but I still think it's worth considering.

Rich


More information about the uClibc mailing list