On Mon, Dec 12, 2011 at 5:54 AM, David Coppa <[email protected]> wrote: > While working on enabling upnp/natpmp support into net/mldonkey, > I've found we miss pthread_mutex_timedlock(). > > For now I've the diff below, which is ripped/adapted from xine-lib, > and it seems to do the trick... > > Would it be useful to add it to libpthread?
I think it would be useful to add an implementation of pthread_mutex_timedlock() to libpthread and librthread. I don't think the implementation you cited for libpthread should be added as is, as I don't believe it meets the requirements of the standard as it doesn't "determine eligibility for processing resources by the scheduling policy". In particular, a high priority FIFO or RoundRobin thread that calls pthread_mutex_timedlock() should obtain the lock before a low priority thread that calls pthread_mutex_lock(), but that's not true with the polling implementation. That's not a slam on that implementation; it's basically the best you can do portably. I believe pthread_mutex_timedlock() can be implemented efficiently inside libpthread using it's existing internal timeout mechanism. It would mean changing the internal thread state of PS_MUTEX_WAIT to permit a timeout, like PS_COND_WAIT does, but that doesn't look complicated. The librthread implementation is actually easier. I might add it there before anyone does libpthread, just because. :-) While I'll willingly review an efficient implementation for libpthread, I've personally sworn off spending time enhancing it. Sorry. > Reference is at: > http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_timedlock.html (Hmm, that's the old POSIX.1-2004 link; you should update your bookmarks to the 2008 version of the standard. In this case, the link is http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html ) Philip Guenther
