On Feb 21, 9:59 pm, "Hunk" <santosh.udyav...@gmail.com> wrote:
> On Feb 21, 7:55 pm, "Bharath" <cbku...@gmail.com> wrote:
>
>
>
>
>
> > On Feb 21, 3:08 am, "Hunk" <santosh.udyav...@gmail.com> 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