Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Concurrency issues in reader-writer problem

Reply
Thread Tools

Concurrency issues in reader-writer problem

 
 
Hunk
Guest
Posts: n/a
 
      02-21-2007
Hi

I would like some ideas on way to solve the concurrency issue. The
problem is , I have an object say X which multiple readers need to
access and also to update. They do so by say two functions :
// simplistic view of the problem
Read()
{
return X;
}

Update(Y)
{
X= Y;
}

Now I would like to block any reader while calling update. With the
general solutions provided of having say a mutex and using it in Read
and Update would solve the problem. But then this would block multiple
readers also which is not desired. i.e a block on read should be
allowed only when update is called. Having a boolean and checkin is
not ideal as the atomicity of the operation is not guaranteed. Any
ideas on this?

 
Reply With Quote
 
 
 
 
dasjotre
Guest
Posts: n/a
 
      02-21-2007
On 21 Feb, 11:08, "Hunk" <(E-Mail Removed)> wrote:
> Hi
>
> I would like some ideas on way to solve the concurrency issue. The
> problem is , I have an object say X which multiple readers need to
> access and also to update. They do so by say two functions :
> // simplistic view of the problem
> Read()
> {
> return X;
>
> }
>
> Update(Y)
> {
> X= Y;
>
> }
>
> Now I would like to block any reader while calling update. With the
> general solutions provided of having say a mutex and using it in Read
> and Update would solve the problem. But then this would block multiple
> readers also which is not desired. i.e a block on read should be
> allowed only when update is called. Having a boolean and checkin is
> not ideal as the atomicity of the operation is not guaranteed. Any
> ideas on this?


you nead reader-writer lock. the best implementation I've
seen is Valery Pryamikov's mrsw_guard

 
Reply With Quote
 
 
 
 
Bharath
Guest
Posts: n/a
 
      02-21-2007
On Feb 21, 3:08 am, "Hunk" <(E-Mail Removed)> wrote:
> Hi
>
> I would like some ideas on way to solve the concurrency issue. The
> problem is , I have an object say X which multiple readers need to
> access and also to update. They do so by say two functions :
> // simplistic view of the problem
> Read()
> {
> return X;
>
> }
>
> Update(Y)
> {
> X= Y;
>
> }
>
> Now I would like to block any reader while calling update. With the
> general solutions provided of having say a mutex and using it in Read
> and Update would solve the problem. But then this would block multiple
> readers also which is not desired. i.e a block on read should be
> allowed only when update is called. Having a boolean and checkin is
> not ideal as the atomicity of the operation is not guaranteed. Any
> ideas on this?


Is this a multi-threaded program? If it is, the best solution is to
use read-write locks in pthread library. See the manpage of
pthread_rwlock_wrlock and pthread_rwlock_rdlock. Note that you need to
have -DUSE_UNIX98 in your compiler flags.

 
Reply With Quote
 
Hunk
Guest
Posts: n/a
 
      02-22-2007
On Feb 21, 7:55 pm, "Bharath" <(E-Mail Removed)> wrote:
> On Feb 21, 3:08 am, "Hunk" <(E-Mail Removed)> wrote:
>
>
>
>
>
> > Hi

>
> > I would like some ideas on way to solve the concurrency issue. The
> > problem is , I have an object say X which multiple readers need to
> > access and also to update. They do so by say two functions :
> > // simplistic view of the problem
> > Read()
> > {
> > return X;

>
> > }

>
> > Update(Y)
> > {
> > X= Y;

>
> > }

>
> > Now I would like to block any reader while calling update. With the
> > general solutions provided of having say a mutex and using it in Read
> > and Update would solve the problem. But then this would block multiple
> > readers also which is not desired. i.e a block on read should be
> > allowed only when update is called. Having a boolean and checkin is
> > not ideal as the atomicity of the operation is not guaranteed. Any
> > ideas on this?

>
> Is this a multi-threaded program? If it is, the best solution is to
> use read-write locks in pthread library. See the manpage of
> pthread_rwlock_wrlock and pthread_rwlock_rdlock. Note that you need to
> have -DUSE_UNIX98 in your compiler flags.- Hide quoted text -
>
> - Show quoted text -


Thanks... yes it is a multithreaded program. i'll take a look at the
reader writer locks mentioned. Any idea on how this is implemented in
zthreads?

 
Reply With Quote
 
Bharath
Guest
Posts: n/a
 
      02-22-2007
On Feb 21, 9:59 pm, "Hunk" <(E-Mail Removed)> wrote:
> On Feb 21, 7:55 pm, "Bharath" <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Feb 21, 3:08 am, "Hunk" <(E-Mail Removed)> wrote:

>
> > > Hi

>
> > > I would like some ideas on way to solve the concurrency issue. The
> > > problem is , I have an object say X which multiple readers need to
> > > access and also to update. They do so by say two functions :
> > > // simplistic view of the problem
> > > Read()
> > > {
> > > return X;

>
> > > }

>
> > > Update(Y)
> > > {
> > > X= Y;

>
> > > }

>
> > > Now I would like to block any reader while calling update. With the
> > > general solutions provided of having say a mutex and using it in Read
> > > and Update would solve the problem. But then this would block multiple
> > > readers also which is not desired. i.e a block on read should be
> > > allowed only when update is called. Having a boolean and checkin is
> > > not ideal as the atomicity of the operation is not guaranteed. Any
> > > ideas on this?

>
> > Is this a multi-threaded program? If it is, the best solution is to
> > use read-write locks in pthread library. See the manpage of
> > pthread_rwlock_wrlock and pthread_rwlock_rdlock. Note that you need to
> > have -DUSE_UNIX98 in your compiler flags.- Hide quoted text -

>
> > - Show quoted text -

>
> Thanks... yes it is a multithreaded program. i'll take a look at the
> reader writer locks mentioned. Any idea on how this is implemented in
> zthreads?- Hide quoted text -
>
> - Show quoted text -


I never used zthreads but this link might help.
http://zthread.sourceforge.net/html/...WriteLock.html

 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-23-2007
"dasjotre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On 21 Feb, 11:08, "Hunk" <(E-Mail Removed)> wrote:

[...]
> you nead reader-writer lock. the best implementation I've
> seen is Valery Pryamikov's mrsw_guard


how does it compare to the following algorithm:


 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-23-2007
DOH! sorry for the other msg... I left out the link!

"dasjotre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On 21 Feb, 11:08, "Hunk" <(E-Mail Removed)> wrote:

[...]
> you nead reader-writer lock. the best implementation I've
> seen is Valery Pryamikov's mrsw_guard


how does it compare to the following algorithm:

http://groups.google.com/group/comp....fb0ed46a4bcb4b


 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-23-2007
"Hunk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi
>
> I would like some ideas on way to solve the concurrency issue.


Sure:

http://groups.google.com/group/comp....6ad37c34dd673a

http://groups.google.com/group/comp....fb0ed46a4bcb4b

http://appcore.home.comcast.net/


How about we transfer this thread over to comp.programming.threads before we
go any further?


 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-23-2007
A while back I was thinking about fully integrating a working solution to
the reader-writer problem directly into the C++ STL:

http://groups.google.com/group/comp....c9c2673682d4cf


 
Reply With Quote
 
Chris Thomasson
Guest
Posts: n/a
 
      02-23-2007
"Chris Thomasson" <(E-Mail Removed)> wrote in message
news(E-Mail Removed). ..
> DOH! sorry for the other msg... I left out the link!
>
> "dasjotre" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
>> On 21 Feb, 11:08, "Hunk" <(E-Mail Removed)> wrote:

> [...]
>> you nead reader-writer lock. the best implementation I've
>> seen is Valery Pryamikov's mrsw_guard

>
> how does it compare to the following algorithm:
>
> http://groups.google.com/group/comp....fb0ed46a4bcb4b


Or this rw-spinlock implementation:

http://appcore.home.comcast.net/appc...k_algo1_c.html

http://appcore.home.comcast.net/appc...k_algo1_h.html


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
open source with concurrency issues igor Java 0 08-11-2008 07:57 PM
Custom Http Handler Factory and Possible Concurrency Issues on Application Start Jordan S. ASP .Net 6 06-02-2008 05:11 PM
Javascript concurrency issues... Ben Kolera Javascript 2 07-13-2006 12:18 AM
concurrency issues (on aspx page in vb) Brian Henry ASP .Net 4 10-09-2003 07:14 AM
concurrency issues Chris Smith Javascript 1 07-28-2003 08:53 PM



Advertisments