Introduction to Multi-Tasking In Interactive C

 

In interactive C, it is quite simple to run talks simultaneously.

 

In fact, the processor is doing something called time splicing where it allocates a splice of time to one process and then another. This makes it seem like the processes are running simultaneously. In other words, the microprocessor may be working on process #1 for 5 milliseconds and then process #2 for 5 milliseconds, then back to process #1 again.

 

 

Commands to know for multi-tasking in IC:

 

int start_process(function());

 

Returns an integer. This integer is the process’ PID. Since multiple processes will be running, each process must be associated to a PID in order to distinguish them.

 

void kill_process(int pib);

 

Kills the process associated to the PID in the function call.

 

Short example from http://www.vorlesungen.uni-osnabrueck.de/informatik/robot00/doc/books/martin.pdf :

 

This short example starts a process to check a sensor, sleeps for 1 second (while still checking the sensor) then kills the process using the PID obtained.

 

void check_sensor(int n){

 

         while (1){

                 printf("Sensor %d is %d\n", n, digital(n));

         }

 

void main(){

         int pid;

 

         pid= start_process(check_sensor(2));

         sleep(1.0);

         kill_process(pid);

}

 

 

To see a longer example of multi-tasking in Interactive C, see Sample Programs.

 

Return To Homepage

 

 

Last Updated July 13th, 2006

By Eric Savoie