flyweigt pattern and concurrency

270 views Asked by At

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

1

There are 1 answers

0
Richard Hodges On BEST ANSWER

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.