ovs-thread: Use fair (but nonrecursive) rwlocks on glibc.
authorBen Pfaff <blp@nicira.com>
Fri, 21 Feb 2014 18:53:49 +0000 (10:53 -0800)
committerBen Pfaff <blp@nicira.com>
Sat, 22 Feb 2014 00:27:10 +0000 (16:27 -0800)
commit6b59b543c840ac82acc4d57f865c0b5e331ac590
tree6da0af0a46ab13351c99257981ac5103f650b553
parent5a0702383b61d329f0640b5b4da4869a4b4f1384
ovs-thread: Use fair (but nonrecursive) rwlocks on glibc.

glibc supports two kinds of rwlocks:

    - The default kind of rwlock always allows recursive read-locks to
      succeed, but threads blocked on acquiring the write-lock are treated
      unfairly, causing them to be delayed indefinitely as long as new
      readers continue to come along.

    - An alternative "writer nonrecursive" rwlock allows recursive
      read-locks to succeed only if there are no threads waiting for the
      write-lock.  Otherwise, recursive read-lock attempts deadlock in
      the presence of blocking write-lock attempts.  However, this kind
      of rwlock is fair to writer.

POSIX allows the latter behavior, which essentially means that any portable
pthread program cannot try to take read-locks recursively.  Since that's
true, we might as well use the latter kind of rwlock with glibc and get the
benefit of fairness of writers.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
lib/ovs-thread.c
lib/ovs-thread.h