How could it? A lot of threads might get to read the boolean with its first value before one of them changed it, and thereafter all the others would be acting on false data. It could only be safe if, somehow, any thread that read the boolean could prevent other threads changing it until it had finished doing everything it had to do that depended on the boolean's value. That's what states are for.
Here is how I explain states to myself, in case it helps: states allow us to give objects alternative sets of events.
Every type of object has a certain list of events - OnActivate, OnUpdate and so on. But these are actually the events that fire in the empty state. They could more accurately be called 'OnActivateWhileInTheEmptyState', 'OnUpdateWhileInTheEmptyState', only it would be a dreadful chore to have to type all that.
When you create a state you are creating another set of events the object will respond to. So this:
State Busy Event OnUpdate() endEventendState
is creating an event that could be called 'OnUpdateWhileInTheBusyState'. And when you say
GotoState("Busy")
you're saying that, from now on, events in the busy state, when they exist, will be fired instead of events in the empty state.
Here's an example:
Event OnUpdate() GotoState("Busy") int AnInt = 1 DoSomethingThatMightAffectAnInt() if AnInt == 1 DoSomethingElse() endIf GotoState("")endEventState Busy Event OnUpdate() endEventendState
Without the gotostate, while this code was away DoingSomethingThatMightAffectAnInt, another OnUpdate event might start, and set AnInt back to one again. But thanks to the
GotoState("Busy")
when an OnUpdate event is started it will be an 'OnUpdateWhileInTheBusyState', which does not set AnInt to 1, rather than 'OnUpdateWhileInTheEmptyState', which does. Once we are safely passed the code which cares about AnInt's value, we can go back to using 'OnUpdateWhileInTheEmptyState', by calling GotoState("").