c++ - Best approach to synchronising properties across threads -


I am looking for some advice on the best ways to synchronize access to the properties of an object in C ++. The application contains an internal cache of objects that has 10 properties. These objects should be requested in those sets whose properties can be modified and saved again. They can be reached at any time by 2-4 threads, but access is not so intense, so my options are:

  1. Using the important section, property accessories for each object Lock on It means a lot of important sections - one for each object.

  2. Return the copies of the objects to update the object properties and an update function that locks the same important section appropriate.

I think option 2 seems most efficient, but I have to see if I remember a hidden 3 option which would be more suitable.

Thank you, J

First of all, I think that you Concerned about How do you know the barriers to your code due to locking or copying? Important sections are very light and do not cause too much ground, or at least not as much as you think. Simply use the lightest locking primitive available if you hope for your system to run on multi-processor hardware, you can also use spinlock.

Secondly, worry about the simplicity of your millennium model before the demonstration (Hint: simple model is easy to understand, to get right and to adapt) So if you can buy it, then You can take copies of objects, this will reduce the pain of running race situations, if you are making complex changes on the object set, which depends on the previous several values.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -