Best approach to synchronising properties across threads
Posted
by user290796
on Stack Overflow
See other posts from Stack Overflow
or by user290796
Published on 2010-06-14T08:56:37Z
Indexed on
2010/06/14
11:32 UTC
Read the original article
Hit count: 172
Hi,
I'm looking for some advice on the best approach to synchronising access to properties of an object in C++. The application has an internal cache of objects which have 10 properties. These objects are to be requested in sets which can then have their properties modified and be re-saved. They can be accessed by 2-4 threads at any given time but access is not intense so my options are:
Lock the property accessors for each object using a critical section. This means lots of critical sections - one for each object.
Return copies of the objects when requested and have an update function which locks a single critical section to update the object properties when appropriate.
I think option 2 seems the most efficient but I just want to see if I'm missing a hidden 3rd option which would be more appropriate.
Thanks, J
© Stack Overflow or respective owner