Obtaining task exit code

The following example shows how to obtain task exit code.

#include <stdio.h>
#include "OS_API.h"


ERROR WorkerTask(PVOID Arg)
{
  /* Mark parameter as unused */
  AR_UNUSED_PARAM(Arg);

  /* Task finishes work and returns exit error code */
  return ERR_INVALID_PARAMETER;
}


ERROR MainTask(PVOID Arg)
{
  ERROR ExitCode;
  HANDLE TaskHandle;

  /* Mark parameter as unused */
  AR_UNUSED_PARAM(Arg);

  /* Create task */
  TaskHandle = osCreateTask(WorkerTask, NULL, 0, 1, FALSE);

  /* Wait for task completion */
  osWaitForObject(TaskHandle, OS_INFINITE);

  /* Obtain task exit code */
  osGetTaskExitCode(TaskHandle, &ExitCode);

  /* Print task exit code */
  printf("Task exit code: %i.\n", (int) ExitCode);
  return ERR_NO_ERROR;
}


int main(void)
{
  /* Initialization */
  arInit();
  stInit();
  osInit();

  /* Create main task */                       
  osCreateTask(MainTask, NULL, 0, 0, FALSE);

  /* Start the operating system */
  osStart();

  /* Deinitialization */
  osDeinit();
  arDeinit();
  return 0;
}
SpaceShadow documentation