PDA

View Full Version : state machine in its own thread



shaolin
31st May 2011, 09:30
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

wysota
31st May 2011, 10:14
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).

shaolin
1st June 2011, 12:12
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..

MarekR22
1st June 2011, 14:56
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.

wysota
1st June 2011, 15:34
State machines can represent anything, they don't have to be related to the UI.

MarekR22
1st June 2011, 16:22
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.

wysota
1st June 2011, 17:30
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.

shaolin
4th June 2011, 13:45
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?