Results 1 to 8 of 8

Thread: state machine in its own thread

  1. #1
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default state machine in its own thread

    Hi guys,

    I'm starting to play with the state machine framework. Qt doc says that

    The state machine executes asynchronously, i.e. it becomes part of your application's event loop.
    I am not sure but I think this means that the state machine lives in the main thread, so for example if I have 10.000 state machines reacting at the same signal, it will load only one CPU core.

    If so, can I start a state machine in a secondary thread? Is there any side effect in doing this?

    Thx

  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: state machine in its own thread

    You can do that but it won't change the fact that the signal will have to be dispatched 10.000 times and it will be done in a single thread. If that's the only rationale of starting 10.000 threads, I would think 10.000 times before doing so (you won't be able to start 10.000 threads anyway).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    shaolin (1st June 2011)

  4. #3
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: state machine in its own thread

    Yes, probably the best thing to do is, where possible, executing the response slot in a separate thread but using qtconcurrent and the ready to use pool of threads until all machines are done..

  5. #4
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: state machine in its own thread

    Strange, I always thought that Qt state machine framework should be used to represent state of UI, so 10 000 state machines it is unusual (odd) requirement.

  6. #5
    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: state machine in its own thread

    State machines can represent anything, they don't have to be related to the UI.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: state machine in its own thread

    Yes I know, I'm just saying that Qt state machine framework is designed for UIs (that is why it supports animations). Using this framework to other demanding tasks IMHO looks like a bad choice.

  8. #7
    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: state machine in its own thread

    Quote Originally Posted by MarekR22 View Post
    Yes I know, I'm just saying that Qt state machine framework is designed for UIs (that is why it supports animations).
    No, I mean Qt state machines can be related to anything, not just the UI. And you can animate anything (like the pitch of sound or voltage given to a device) and not only position and opacity of UI elements.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: state machine in its own thread

    yes, the animation framework is essentially a big, more or less complex, interpolator. you can pass everything to it.

    little OT: do you know why I can't receive email from the forum even if my user settings are correct?

Similar Threads

  1. State Machine returning to previous state
    By akiross in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2011, 00:39
  2. Replies: 0
    Last Post: 19th December 2010, 16:03
  3. State machine inside a QWidget
    By leoalvesmachado in forum Newbie
    Replies: 10
    Last Post: 4th August 2010, 18:36
  4. State machine implementation
    By yyiu002 in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2010, 04:57
  5. How to get this Qt state machine to work?
    By blukske in forum Qt Programming
    Replies: 0
    Last Post: 1st April 2010, 10:15

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.