Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #496

Re: Locks for rarely changed data

From "Naveen K. Kaushik" <naveenkumarkaushik@gmail.com>
Newsgroups comp.programming.threads
Subject Re: Locks for rarely changed data
Date 2011-08-09 11:05 +0530
Organization A noiseless patient Spider
Message-ID <4E40C718.9010407@gmail.com> (permalink)
References <2716c873-a080-407a-88e8-a52904372920@h21g2000pre.googlegroups.com>

Show all headers | View raw


On 05-08-2011 PM 03:10, itt ium wrote:
> Group,
>
> I have a multithreaded software, that uses large amount of
> configuration data that is rarely modified (on the average  once in
> 2-3 days). This data is kept in the form of STL map, hash map etc
> which are not thread safe. Although data is rarely changed, we have to
> still protect it. Profiling data showed, good amount of CPU cycles
> used in locking/unlocking.
>
> I was thinking of giving separate copy of data to all the threads. A
> configuration chnage event will be delivered to each thread and thread
> then can read the new/modified configuration. In this way mutex will
> not be needed.
>
> Is there any other model of handling such a data without any locks.
>
> Because of the relevance I am posting the message to following groups.
>
>
> thanks
> Ittium

Theoretically, If data is rarely changed you can use reader/writer lock, 
practically it may not be a good idea, since reader/writer lock may not 
be less expensive than mutex and you can justify their usage only if 
readers are holding the data for large amount of time.

In one of our project, we were keeping the configuration data in the 
non-volatile memory, to read the data we will send the signal to the 
process. Signal handler will set the flag, in that case different 
threads will update their configuration data by reading from NV memory.
Thread will have their own copy of configuration data as suggested. 
Using this technique, you can avoid the locks.

Naveen

Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Locks for rarely changed data itt ium <ittium@gmail.com> - 2011-08-05 02:40 -0700
  Re: Locks for rarely changed data "Naveen K. Kaushik" <naveenkumarkaushik@gmail.com> - 2011-08-09 11:05 +0530
  Re: Locks for rarely changed data Robert Wessel <robertwessel2@yahoo.com> - 2011-08-09 02:07 -0500
  Re: Locks for rarely changed data David Schwartz <davids@webmaster.com> - 2011-08-10 12:34 -0700
    Re: Locks for rarely changed data itt ium <ittium@gmail.com> - 2011-08-12 00:04 -0700

csiph-web