You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a beginner in C. I'm familiar with nats from go, but am hoping someone can answer the following question for me...
The question:
If I have a single nats connection called 'nc', and I have multiple publishers and multiple subscribers all in the same thread... do I need to protect anything with mutex locking?
In case it's relevant:
the subscribers would be using natsSubscription_NextMsg with a timeout of 0 as I want a non-blocking subscription.
both my publishers and subscribers would be publishing/subscribing to various subjects
Thanks a lot for any help
The text was updated successfully, but these errors were encountered:
All calls use internal locking where needed. As a user, you would need to do your own locking if you were to share the same callback with different subscribers (since the callback would be invoked from different threads for each subscriber). Note that this is true for any kind of callback that exist in C NATS. For instance, connection or error handlers, etc.. if you specify the same callback to different objects you take the risk that the code in that callback may be executed from different internal threads.
Since you are planning on using synchronous subscriptions, then you should not need any user-level locking. Note regarding natsSubscription_NextMsg with a timeout of 0: it means that if a message is already available in the internal queue, then you will get the message, otherwise you will get NATS_TIMEOUT.
Hi
I'm a beginner in C. I'm familiar with nats from go, but am hoping someone can answer the following question for me...
The question:
If I have a single nats connection called 'nc', and I have multiple publishers and multiple subscribers all in the same thread... do I need to protect anything with mutex locking?
In case it's relevant:
Thanks a lot for any help
The text was updated successfully, but these errors were encountered: