MutliThread application and cuncurrent data access



  • Hi all,
    I have some doubts in multithread data access:

    1. What does it happens if 2 threads read same data in memory without synchronization? does the application crash?
    2. What does it happens if 2 threads write data in the same memory area? does the application crash or I only get possible wrong data in the memory?

  • Moderators

    Hi,

    I recommend reading http://doc-snapshot.qt-project.org/qt5-stable/threads-synchronizing.html

    1. If the data is guarantee to not change while it's being read, this is fine. See the description for QReadWriteLock in the link above.

    2. You will probably get data corruption. Data corruption can cause crashes, or it can fail silently -- this depends on your code. Note: In these situations, crashes are good because they tell you that something is wrong. If your app DOESN'T crash, then you won't know if your data is destroyed.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.