Шаблон проектирования, модель/представление Qt и несколько потоковC++

Программы на C++. Форум разработчиков
Ответить
Гость
 Шаблон проектирования, модель/представление Qt и несколько потоков

Сообщение Гость »


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
. 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)
    and

    Код: Выделить всё

    updateStockScreen(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


Источник: https://stackoverflow.com/questions/948 ... le-threads
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»