From 2d3f49ebd38d6441b693d51adcf071088817ddf5 Mon Sep 17 00:00:00 2001 From: mtm Date: Mon, 19 Jan 2004 14:51:45 +0000 Subject: Implement reference counting of read-write locks. This uses a list in the thread structure to keep track of the locks and how many times they have been locked. This list is checked on every lock and unlock. The traversal through the list is O(n). Most applications don't hold so many locks at once that this will become a problem. However, if it does become a problem it might be a good idea to review this once libthr is off probation and in the optimization cycle. This fixes: o deadlock when a thread tries to recursively acquire a read lock when a writer is waiting on the lock. o a thread could previously successfully unlock a lock it did not own o deadlock when a thread tries to acquire a write lock on a lock it already owns for reading or writing [ this is admittedly not required by POSIX, but is nice to have ] --- lib/libthr/thread/thr_exit.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/libthr/thread/thr_exit.c') diff --git a/lib/libthr/thread/thr_exit.c b/lib/libthr/thread/thr_exit.c index facd707..41b1f86 100644 --- a/lib/libthr/thread/thr_exit.c +++ b/lib/libthr/thread/thr_exit.c @@ -122,6 +122,12 @@ _pthread_exit(void *status) _thread_cleanupspecific(); } + /* + * Remove read-write lock list. It is allocated as-needed. + * Therefore, it must be checked for validity before freeing. + */ + if (curthread->rwlockList != NULL) + free(curthread->rwlockList); retry: /* * Proper lock order, to minimize deadlocks, between joining -- cgit v1.1