Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/24/08 08:59
Read: times


 
#158570 - statemachine
Responding to: ???'s previous message
What usually goes hand-in-hand with a super-loop is the notion of state-machines. Every 'thread' in your mindset can be implemented as a state-machine. And all state-machines are called sequentially in the super-loop. Obviously the state-machines may not lock up. Together they perform a form of cooperative multitasking.

enum Tstate {IDLE, ACTIVE};

void task1(void)
{
    static enum Tstate state = 0;

// Any 'while' statement in here could possibly cause a lock-up!

    switch (state)
    {
        case IDLE:
            if (key==1)
                state = ACTIVE;
            break;
        case ACTIVE:
            if (key==2)
                state = IDLE;
            break;
    }
}

void main(void)
{
    while (1)
    {
        task1();
        task2();
    }
}
Maarten

List of 22 messages in thread
TopicAuthorDate
Multi Threading in C for 89S8253            01/01/70 00:00      
   effective?            01/01/70 00:00      
   Protothreads            01/01/70 00:00      
   What do you mean?            01/01/70 00:00      
   What actually you are looking for            01/01/70 00:00      
      Seek Help ! for Serial Communication            01/01/70 00:00      
         start a new thread            01/01/70 00:00      
            Good reply...            01/01/70 00:00      
               hehe...            01/01/70 00:00      
                  purpose            01/01/70 00:00      
                     What tasks?            01/01/70 00:00      
                        tasks            01/01/70 00:00      
                           Superloop            01/01/70 00:00      
                              ok...one more thing            01/01/70 00:00      
                                 If Key == '1' Then            01/01/70 00:00      
                                    statemachine            01/01/70 00:00      
                                       An alternative            01/01/70 00:00      
                                          why not in FAQ or personal page?            01/01/70 00:00      
                                             Yes            01/01/70 00:00      
   An alternative ?            01/01/70 00:00      
      Your Mileage May Vary            01/01/70 00:00      
   thanks alot            01/01/70 00:00      

Back to Subject List