I am creating an application which displays the market data and uses it in some other forms too. I store market data in a map say
std::map<tickerId, StockData>
. Let me give one used case of how this map can be used.
- network sends a data packet encapsulating the stock Data at time t.
updatePrice(tickerId, latestPrice)
- update the stock data in the map. Now, multiple threads can access/update the data. So the map has to be locked for thread-safe operations. Here is the first question, do I need to lock the underlying data too for updates?
- There are multiple uses of the new stock data, say, there is a price update on IBM, then I need to update the value of IBM in my portfolio. As well as display the new data on a screen. And there can be several other simultaneous uses.
updatePosition(tickerId, price)
andupdateStockScreen(tickerId, price)
. Also, separting Gui updates from position update is important as GUI is not the main strength of the application. - I am just troubled about how to implement this type of design. I read about Model/View Design in QT to display data but if View thread reads from the same map, it has to be locked. This leads to an slow/inefficient design. Every time view reads from the model, the model needs to be locked. Is this preffered in real-time GUIs?
- To summarize, I have stored a lot of different objects as maps. And objects are updated in realtime. I need to update them and then use them at various locations. It would be great if someone can give me a small example on how to implement such designs.
Some references to useful books are appreciated too.
I am new and trying to achieve too much with my little knowledge so forgive me if I have asked stupid/ill-formed questions.
Thanks Shiv
See Question&Answers more detail:os