• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[OT] Finite vs Infinite State Machines?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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

  • Follow-Ups:
    • Re: [OT] Finite vs Infinite State Machines?
      • From: Graham Cox <email@hidden>
References: 
 >TextField not updated in a sheet for document-based Cocoa app (From: Gilles Celli <email@hidden>)
 >Re: TextField not updated in a sheet for document-based Cocoa app (From: Graham Cox <email@hidden>)
 >Re: TextField not updated in a sheet for document-based Cocoa app (From: Gilles Celli <email@hidden>)

  • Prev by Date: Re: NSTextField Tab Order.
  • Next by Date: Re: Sandoxing: Creating a security-scoped bookmark for contents of a user-specified directory.
  • Previous by thread: Re: TextField not updated in a sheet for document-based Cocoa app
  • Next by thread: Re: [OT] Finite vs Infinite State Machines?
  • Index(es):
    • Date
    • Thread