[OT] Finite vs Infinite State Machines?
[OT] Finite vs Infinite State Machines?
- Subject: [OT] Finite vs Infinite State Machines?
- From: Dave <email@hidden>
- Date: Wed, 13 Jun 2012 23:03:35 +0100
Hi,
I'm interested how people will comment on this.
A Finite State Machine Implementation would look something like this:
-(void) nextState
{
lastState = currentState;
currentState = nextState;
switch (currentState)
{
// Do Something to make nextState get called again, e.g. set of an
ASync Request.
case: kCaseA
[self doSomethingCaseA];
nextState = kCaseB;
break;
case: kCaseB
[self doSomethingCaseB_UsingDataFromCaseA:caseAData];
nextState = kCaseC;
break;
case: kCaseC
[self doSomethingCaseC_UsingDataFromCaseB:caseCData];
nextState = kLastState;
break;
case: kLastState
return;
break;
default:
//UNKNOWN STATE
}
}
-(void) doStateMachine
{
lastState = UNKNOWN_STATE;
currentState = kCaseA;
[self nextState];
}
The above assumes the doSomethingCase Methods will set of some ASync
Task that will call nextState sometime in the future.
However an Infinite State Machine would look something like this:
-(void) doStateMachine
{
myDataFromCaseA = [self doSomethingCaseA];
myDataFromCaseB = [self doSomethingCaseB_UsingDataFromCaseA:
myDataFromCaseA];
myDataFromCaseC = [self doSomethingCaseC_UsingDataFromCaseB:
myDataFromCaseB];
}
In this case, the doSomethingCase methods are causing the thread to
wait until the ASync Response has completed and the data has been
obtained.
Since there is no formal definition of the number of states here,
could be said to be an Infinite State Machine? I've been programming
since the days of mini computers in assembler. In assembler this
would be implemented is using an "Exchange Instruction" to alter the
PC on the stack and cause it to return to the correct place once the
ASync Task (usually an interrupt) had finished.
I also think RBK Dewar refers to this technique as an "Infinite State
Machine".
Any comments welcomed.
Cheers
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden