readwrite lock with read reentrant

J

jj_online

This is not a C++ specific issue. However, I am trying to implement a
readwritelock in C++ and hence would like to get help from this
group.

a readwritelock allows shared lock among all readers and exclusive
lock for a single writer. After implemented, I realized that the
writer may suffer starvation: readers can continuously get shared lock
and hence writer will wait indefinitely. so I added a writer wait
count and prevent reader acquiring shared lock as soon as a writer is
waiting. But this has serious issue: it prevents reader reentrant: a
reader already has shared lock should be able to get shared lock
again. Without reader reentrant, a reader and a writer will deadlock.

Any advice on how to resolve this issue: a writer cannot starve and
reader can reentrant?

Thanks.
 
V

Victor Bazarov

jj_online said:
This is not a C++ specific issue. However, I am trying to implement a
readwritelock in C++ and hence would like to get help from this
group.

a readwritelock allows shared lock among all readers and exclusive
lock for a single writer. [..]

Try comp.programming.threads. Your issue is not related to C++ at
all and as such OT here, sorry.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top