Results 1 to 6 of 6

Thread: dangerous QThread

  1. #1
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default dangerous QThread

    well, I have a main thread with QApplication exec()-ing and then I start a secondary QThread. There something very bad might happen (for example attempt to read data of another process, which isn't catched even with catch(...)). Are there any means to make OS terminate not the whole process, but only the secondary thread and send appropriate signal to the main thread? I'd be happy for WinXP/Vista and Linux solution, but cross-platform (as Qt itself) solution would be ideal. Thanks in advance!

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

    Default Re: dangerous QThread

    Don't you think it would be better to implement your application in such a way that it doesn't do things that are not allowed?

    As threads share memory space, if one of them tries to corrupt the memory, the whole process has to be terminated. If you wish to avoid that, you have to make sure each of the execution flows has its own memory space, for example by using separate processes instead of separate threads. You can then use one of many available IPC mechanisms to communicate between the processes.

  3. #3
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: dangerous QThread

    If it is only ATTEMPT to corrupt memory, the main thread shouldn't be corrupted after the termination of the secondary thread afaik. The sec.thread has its own code and stack segments, OS clear them and then pass the control to the main thread, perhaps notifying it "oops I've just killed your child".
    Anyway I've just discovered SEH exceptions, I suppose it will help.

    What do you think, which errors may rise while reading corrupted binary file of complex structure (ints, floats, strings, bitmaps etc)?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dangerous QThread

    Quote Originally Posted by Radagast View Post
    What do you think, which errors may rise while reading corrupted binary file of complex structure (ints, floats, strings, bitmaps etc)?
    mostly buffer overruns, but depends what/how you read... you could implement a completely safe file loader... all applications have mechanisms to detect corrupted files.
    I just think you're trying to reinvent the wheel there.

  5. #5
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: dangerous QThread

    I mean loading with QFile and QDataStream:perator<<
    wheel..perhaps. I'm new to Qt

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

    Default Re: dangerous QThread

    Quote Originally Posted by Radagast View Post
    If it is only ATTEMPT to corrupt memory, the main thread shouldn't be corrupted after the termination of the secondary thread afaik.
    If there is at least one case when this is not true, then this whole statement is not true. And there is at least one case when this is not true, for instance when writing to an area of memory that is protected from write access - you might write some data and then reach the protected page/segment/area - the application did something that it shouldn't have and thus should be terminated.

Similar Threads

  1. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 13:06
  2. QThread and QSqlDatabase
    By pdoria in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2008, 03:25
  3. Spawn a QThread in another QThread
    By david.corinex in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2007, 12:54
  4. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.