diff options
author | Sergei Golubchik <serg@mysql.com> | 2008-11-04 14:09:32 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mysql.com> | 2008-11-04 14:09:32 +0100 |
commit | 8a655c6042aeb55d24e5cb104bdeec348f57bc9f (patch) | |
tree | 4dc6c1220a82c713816e2b2f540b4c1867408a06 /include/waiting_threads.h | |
parent | f91219ed47604ac80c378bd917431fa42e4cb1d9 (diff) | |
download | mariadb-git-8a655c6042aeb55d24e5cb104bdeec348f57bc9f.tar.gz |
comment
include/waiting_threads.h:
comment with a deadlock example
Diffstat (limited to 'include/waiting_threads.h')
-rw-r--r-- | include/waiting_threads.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/include/waiting_threads.h b/include/waiting_threads.h index a5c22bbcbf1..e872a6b6ab8 100644 --- a/include/waiting_threads.h +++ b/include/waiting_threads.h @@ -80,7 +80,31 @@ typedef struct st_wt_resource { #ifdef WT_RWLOCKS_USE_MUTEXES /* we need a special rwlock-like 'lock' to allow readers bypass - waiting writers, otherwise readers can deadlock. + waiting writers, otherwise readers can deadlock. For example: + + A waits on resource x, owned by B, B waits on resource y, owned + by A, we have a cycle (A->x->B->y->A) + Both A and B start deadlock detection: + + A locks x B locks y + A goes deeper B goes deeper + A locks y B locks x + + with mutexes it would deadlock. With rwlocks it won't, as long + as both A and B are taking read locks (and they do). + But other threads may take write locks. Assume there's + C who wants to start waiting on x, and D who wants to start + waiting on y. + + A read-locks x B read-locks y + A goes deeper B goes deeper + => C write-locks x (to add a new edge) D write-locks y + .. C is blocked D is blocked + A read-locks y B read-locks x + + Now, if a read lock can bypass a pending wrote lock request, we're fine. + If it can not, we have a deadlock. + writer starvation is technically possible, but unlikely, because the contention is expected to be low. */ |