Results 1 to 5 of 5

Thread: Sub-Threading

  1. #1
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Smile Sub-Threading

    Is there any method other than exec to ensure that a thread's event loop will get processor time?

    My issue is this:

    I am starting a thread in the run method of another, but that thread doesn't seem to get processed. Right now I am use a while loop with msleep(10) for blocking.

  2. #2
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Sub-Threading

    You have no way of _guaranteeing_ any thread execution time; that only works in real-time operating systems, and I'm going to assume you're not running one ;-).

    If you can show some code, maybe it's easier to see what's going on. The only two things that pop to my mind are that both threads are running, but one is blocked somehow, or that only one thread is running. Maybe you're passing LowestPriority and the OS isn't scheduling the thread, but that's very unlikely.

    So, code please :-).
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  3. The following user says thank you to Bitto for this useful post:

    TheGrimace (7th June 2007)

  4. #3
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Sub-Threading

    I worked it out with a co-worker. It turns out the following was happening:

    Main thread started sub-thread.

    Main thread called stop on thread after receiving a specific signal. (In this case it was looking for a specific value)

    My main thread called start on it again a couple function calls later.

    The problem was: The main thread never checked to make sure the sub-thread was stopped before moving on. So I got into situations where I was trying to start a thread that was still in the process of stopping.

    I solved it with a simple while loop after the stop commands:

    Qt Code:
    1. while(subThread->isRunning())
    2. {
    3. msleep(1);
    4. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Sub-Threading

    Have you noticed QThread::wait()?
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    TheGrimace (7th June 2007)

  7. #5
    Join Date
    May 2007
    Posts
    90
    Thanks
    40
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sub-Threading

    Yes, but for our program we had to overload the isRunning function call. QWait would work for anyone else with this problem, though.

Similar Threads

  1. Threading and plotting graph in same program.
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th May 2007, 21:42
  2. Newbie threading question
    By deepayan in forum Qt Programming
    Replies: 17
    Last Post: 16th April 2007, 01:25

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.