question

Upvotes
Accepted
43 7 13 12

[EMA CPP] Trade Safety of a class that inherits from OmmConsumerClient

Hi, suppose I have a class that inherits from OmmConsumerClient:

class Client : public thomsonreuters::ema::access::OmmConsumerClient
{
public:
    Client();
    ~Client();
    void onRefreshMsg(const thomsonreuters::ema::access::RefreshMsg&, msg, const thomsonreuters::ema::access::OmmConsumerEvent& event);
    void onUpdateMsg(const thomsonreuters::ema::access::UpdateMsg& msg,const thomsonreuters::ema::access::OmmConsumerEvent& event);
    void onStatusMsg(const thomsonreuters::ema::access::StatusMsg& msg, const thomsonreuters::ema::access::OmmConsumerEvent& event);
};

Now suppose that in one or all of the three methods onRefreshMsg, onUpdateMsg, onStatusMsg I have a list or a map readed and writed in a concurrent way (in others words a critical section). Suppose also that I use the thread of EMA library to dispatch the message for these three callback and not a my own thread (using the OmmConsumerConfig::ApiDispatchEnum).

In this scenario, each critical section (as: lists, maps and so on) must to be locked, for example using a mutex/spin lock? Or the call is made in a thread safe way by EMA library?

For example two call of onRefreshMsg for different notification will be thread safe? or there will be an interleaving giving a race condition for structures managed in the method onRefreshMsg?


Thank you.

elektronrefinitiv-realtimeelektron-sdkema-apirrtapielektron-message-apiOMMmulti-threadingmutex
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
25.3k 87 12 25

Hi @cdefusco

Each instance of the OmmConsumer will only call one instance of onRefresh/onUpdate/onStatus from the same API thread at a time.

As events (such as Refresh / Update / Status) arrive from the server they are stored in an internal queue. The API thread reads each event from the queue one at a time and calls the appropriate event handler. Once your event handler returns control, the API will then read the next event from the queue and call the event handler and so on..

So, even if you have subscribed to multiple RICs, the single instance of OmmConsumer will only call one event handler at a time.

You can read section 2.4 of the EMA Developer Guide for more information.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
11.3k 25 9 14

Hi @cdefusco,

With ApiDispatch mode, the three callback methods; onRefreshMsg, onUpdateMsg, onStatusMsg are invoked by EMA thread. You may need to add a lock for your list or map objects in case that they are accessed by other threads.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ok, so two or more consequent call of onRefreshMsg, for example, are however thread safe, right?

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.