Keil™, An ARM® Company

RL-ARM User's Guide

Multiple Instances

The RTX kernel enables you to run multiple copies of the same task at the same time. These are called multiple instances of the same task. You can simply create and run the same task several times. This is often required when you design a protocol based stack (like ISDN D channel stack).

The following example shows you how the function task2 can run in multiple instances.

#include <rtl.h>

OS_TID tsk_1, tsk2_1, tsk2_2, tsk2_3;
int cnt;

__task void task2 (void) {
  for (;;) {
    os_dly_wait (2);
    cnt++;
  }
}

__task void task1 (void) {
  /* This task will create 3 instances of task2 */
  tsk2_1 = os_tsk_create (task2, 0);
  tsk2_2 = os_tsk_create (task2, 0);
  tsk2_3 = os_tsk_create (task2, 0);
  /* The job is done, delete 'task1' */
  os_tsk_delete_self ();
}

void main (void) {
  os_sys_init(task1);
  for (;;);
}

Note

  • Each instance of the same task must have a unique task ID.