QList and threads crash

  • Hi everyone!

    I have a QList shared between QRunnable objects. I understand QList isn't thread-safe, but before doing anything with it i lock it using QMutexLocker.
    Is it still unsafe to use Qlists in thread with lock mechanism enabled?

    Maybe i missed something, so i'm glad for every opinion. :)

  • As long as you can guarantee that no more than one thread can access the list at the same time you are fine.

  • I'm using
    QMutexLocker locker(&m_mutex);
    // m_mutex is the member of the actual object
    in the only function which access the list.

    I think it should be enough. Do i need take other actions to guarantee safety?

    Edit: i've got it. :) Moved the mutex in a scope that every thread see the same, and then applying the lock mechanism. :)
    Thanks, for the feedback.

Log in to reply

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