Thread: brainstorming with a scheduler.

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    35

    brainstorming with a scheduler.

    The controller which i am using executes code in terms of tasks (Round- robin fashion). It does not got any main function. for example:
    Code:
    int i ; // getting the i value over serial interface
    
    task1(i==0)
    {
      do something;
    }
    
    task2(i==1)
    {
     do something;
    }
    Considering the above situation, when i variable gets value 0 over serial interface task1 evaluates to TRUE and it executes again and again before the value changes to 1. When i variable changes to 1 task2 executes again and again before the value changes to 0. My question is, i want these tasks to execute only once but not again n again.

    What is precisely mean is

    task1(i==0)
    do something but next time only if i changes to 1 and back to 0;

    PS: the i value can only be 1 or 0 and i can improvise the task's condition. for example: task1(i==0 & something)


    Please give your inputs n ideas about solving such problem.

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    32
    Maybe:
    Code:
    int i;
    int task1done = 0;
    int task2done = 0;
    
    while(1) {
       i = getivalue(); // getting the i value over serial interface
    
       if (i==0 && !task1done)
       {
          task1();
          task1done = 1;
          task2done = 0;
       }
     
       if (i==1 && !task2done)
       {
          task2();
          task2done = 1;
          task1done = 0;
       }
     }
    How are you going to interrupt all this process?
    Last edited by Shurik; 12-05-2012 at 10:00 AM. Reason: my perfect English

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    35
    @shurik thanks a ton . That really works in my case. It actually works this way

    Code:
    int i;
    int task1done = 0;
    int task2done = 0;
      /* i dont have to use while(1) as controller takes care of looping 
    and the value received in the task1 over serial interface is used 
    in the execution of rest of tasks. Actually, i am receiving
     over 6 bytes in task1 over SPI and there are over 25 tasks following task1 . */
    
    while(1) {  
    
      task1(getvalue)   
      {
       i = getvalue;
      }
    
       task2 (i==0 && !task1done)
    
       {
          task1();
          task1done = 1;
          task2done = 0;
       }
      
       task3(i==1 && !task2done)
    
       {
          task2();
          task2done = 1;
          task1done = 0;
       }
     }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scheduler in linux
    By anjana in forum Linux Programming
    Replies: 6
    Last Post: 05-29-2007, 12:59 AM
  2. new scheduler in linux
    By anjana in forum Linux Programming
    Replies: 1
    Last Post: 05-28-2007, 02:55 AM
  3. Brainstorming for Stacks Project
    By DarkDot in forum C++ Programming
    Replies: 19
    Last Post: 03-30-2007, 12:54 AM
  4. Brainstorming: How to design this issue?
    By Cristian Negres in forum C++ Programming
    Replies: 5
    Last Post: 08-22-2002, 02:17 AM
  5. Generating structures (brainstorming session)
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 05-07-2002, 12:12 PM