Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QList and threads crash
Forum Updated to NodeBB v4.3 + New Features

QList and threads crash

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fred741
    wrote on last edited by
    #1

    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. :)

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fred741
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved