-2

How can I ensure thread safety in case of the flyweight design pattern. What are the concurrency issues to be concerned about, Are there any standard solutions to these issues. I am looking for solutions with respect to c++

I was trying the normal thread mutex approach during flyweight creation. I was wondering if there are any other points of concern that I was missing out. Also should I prevent flyweight copying. Another concern was as mentioned in the wikipedia Allow concurrent threads to create multiple Flyweight instances thus eliminating contention and allowing multiple instances per value. - is it a good practice to do so

user3282758
  • 1,379
  • 11
  • 29
  • 1
    What is your approach to these issue? Not showing any effort to solve the issue yourself is what gets you downvoted and ignored here... – Ulrich Eckhardt Dec 21 '14 at 11:15
  • I was trying the normal thread mutex approach during flyweight creation. I was wondering if there are any other points of concern that I was missing out. Also should I prevent flyweight copying. Another concern was as mentioned in the wikipedia `Allow concurrent threads to create multiple Flyweight instances thus eliminating contention and allowing multiple instances per value. ` - is it a good practice to do so – user3282758 Dec 21 '14 at 11:31

1 Answers1

2

Flyweight objects are necessarily const objects (since they are shared).
boost has a flyweight library. Suggest you use that rather than reinvent the wheel. Creation and lookup of boost flyweights is thread-safe.

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142