Please nominate your Qt Champions for 2021!

Using data from different thread

  • Hi guys,

    Sorry for if this question was already occurred, it is related to Thread affinity.
    I read "you are doing it wrong" and I am following principles stated there.
    I don't experience app crashes, but just want to be sure.

    Is it safe to directly call data from another thread ? I am aware that I need to use mutex in that case.

    I have a situation that in main thread I am loading Settings from configuration file, and those data I am calling directly in separate thread (when thread is already moved/started).

  • Moderators

    Yes it's OK. If you are 100% sure you won't change that config during runtime, you can even do it without a mutex (but that is quite dangerous for hopefully obvious reasons).

  • Thanks for a replay, I appreciate it...

Log in to reply