Results 1 to 17 of 17

Thread: QMultiHash - crashing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    freeskydiver Guest

    Default Re: QMultiHash - crashing

    I see a small difference. You can use the same object from different threads. You must have a threadsafe call of the functions. This can you do with QMutex for example. Signals/Slots are very nice, but this is a Qt special. In C++ without Qt, you must communicate over threads, too.

  2. #2
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMultiHash - crashing

    Hi,

    I did try using QMutex around the object in question, but to no avail, it still crashed...

    The mutex will just stop the object from being modified by another thread while one thread is updating it. ( AKA Consumer / Producer problem ).

    Regards,
    Steve

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMultiHash - crashing

    Quote Originally Posted by freeskydiver View Post
    I see a small difference. You can use the same object from different threads. You must have a threadsafe call of the functions. This can you do with QMutex for example. Signals/Slots are very nice, but this is a Qt special. In C++ without Qt, you must communicate over threads, too.
    You can't guard an already existing class with mutexes. It's just not possible. You'd have to wrap all calls in all existing classes that call the object in critical sections. The problem is not that your function is not reentrant (because you are working around this particular problem when putting mutexes into your class) but that the object you call is not thread-safe and using mutexes in your code won't help unless you protect every other code that calls the same object. If you miss at least one, you're just calling for trouble (that's one of the problems with protecting code instead of data, by the way).

    So it doesn't matter whether we're talking about Qt or non-Qt applications. If you don't protect everything, you're not protected at all.

  4. #4
    freeskydiver Guest

    Default Re: QMultiHash - crashing

    Quote Originally Posted by wysota View Post
    You can't guard an already existing class with mutexes. It's just not possible. You'd have to wrap all calls in all existing classes that call the object in critical sections.
    Correct thats the only way, but what should I do? When I must use classes who are not thread safe. Ok it's a dangerous way, but possible.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMultiHash - crashing

    It's not possible, if you can't overload every method that calls the object! And this is exactly the case.

  6. #6
    freeskydiver Guest

    Default Re: QMultiHash - crashing

    Quote Originally Posted by wysota View Post
    It's not possible, if you can't overload every method that calls the object! And this is exactly the case.
    That's not essential. When I use a class, then I must encapsulate the calls of the not threadsafe class.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMultiHash - crashing

    Yes, but all calls, not only the ones you make. If you use some kind of architecture (like Qt) it is possible that the architecture calls the objects (like QObjects), which is the exact case here. Thus you can't make QObjects thread-safe just by protecting your code.

  8. #8
    freeskydiver Guest

    Default Re: QMultiHash - crashing

    Upps.... you are right.
    When the system call my object then can it crash.

Similar Threads

  1. Application is Crashing
    By shyam prasad in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 17:04
  2. QSpaceritem problem with crashing
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2006, 19:52
  3. QTableWidget crashing
    By therealjag in forum Qt Programming
    Replies: 5
    Last Post: 19th April 2006, 16:30
  4. QTextCodec decode chinese gb2312 crashing...
    By denny.t in forum Qt Programming
    Replies: 3
    Last Post: 31st March 2006, 06:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.