Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > Re: How to make...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 4043 of 4146
Post > Topic >>

Re: How to make this program more efficient?

by James Kanze <james.kanze@[EMAIL PROTECTED] > Sep 21, 2008 at 10:49 AM

On Sep 21, 2:19 pm, "Chris M. Thomasson" <n...@[EMAIL PROTECTED]
> wrote:
> [comp.programming.threads added]

> "James Kanze" <james.ka...@[EMAIL PROTECTED]
> wrote in message

> news:6edabaf2-df46-49b9-91b6-0dd5c312038d@[EMAIL PROTECTED]
> On Sep 13, 3:18 am, Bill David <billdavi...@[EMAIL PROTECTED]
> wrote:

> > > SUBJECT: How to make this program more efficient?
> > > In my program, a thread will check update from server
> > > periodically and generate a stl::map for other part of this
> > > program to read data from.  Let's name the update method as
> > > doUpdate and stl::map read methods as getData and copyData.
> > > Since stl::map is not thread-safe, we should do
> > > synchronization by ourselves. A usable solution is to create a
> > > boost::mutex::scoped_lock object in all above methods to make
> > > the access to all methods synchronized. But since the doUpdate
> > > method will be executed periodically and the interval may be 1
> > > hour or longer, while all other parts can only read the
> > > stl::map, the above solution may do synchronization too much.
> > > We only need synchronization on all methods when we are
> > > doUpdating.
> > If there's any thread modifying the object, then all accesses
> > must be synchronized.  Period.

> Did you know that readers threads can access data-structures
> without sync?

Not according to Posix, and not on many machines.  Reading
without a sync will probably give you some value, but not
necessarily the last written.

> Or perhaps, any explicit sync whatsoever? No atomic RMW, no
> membars... Think about it. Virtually zero-overhead of reader
> threads indeed. Sounds to good to be true? Why? Perhaps I can
> clarify.

> > Given the usage pattern, it may be more interesting to use a
> > rwlock than a mutex, but this really depends on how long the
> > readers hold the mutex, and how many of them there are.

> Sure. For read-mostly access patterns, WHY use a rwmutex? Did
> you know that rwmutex can be totally suboptimal even in the
> presence of concurrent mutators?

And?  A rwlock, even when acquired for just reading, ensures
memory synchronization.

--
James Kanze (GABI Software)             email:james.kanze@[EMAIL PROTECTED]
 en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
 




 2 Posts in Topic:
Re: How to make this program more efficient?
James Kanze <james.kan  2008-09-21 10:49:18 
Re: How to make this program more efficient?
Jon Harrop <jon@[EMAIL  2008-09-21 21:11:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 9:49:34 CST 2008.