why must POSIX_Init() call exit() rather than use a "return" statement?

Morgan, Keith S morgank at lanl.gov
Tue May 7 14:53:03 UTC 2019


On Monday, May 6, 2019 11:10 PM Sebastian Huber <sebastian.huber at embedded-brains.de> wrote:

> Calling exit() and returning from a POSIX thread are two totally different things.
> If you call exit(), then you terminate the system. If you return from a POSIX
> thread, then this thread exits. The scheduler just picks up the next highest
> priority ready thread. This could be the idle thread.

Ok. This makes sense. I was missing the detail about the idle thread.

However, it seems that the behavior is different between the classic API and the POSIX API. It seems that, in the classic API, terminating a task with a return statement also terminates the system.

Take for example the posix_hello_world example in examples-v2/hello/posix_hello_world and the classic API hello_world_c example in examples-v2/hello/hello_world_c.

Below is the POSIX_Init() function for posix_hello_world. The final call to exit() terminates the simulator as expected. Furthermore, if I replace the final call to exit() with a "return NULL" statement, the simulator does not exit as you have described (presumably it is running the idle thread).

void *POSIX_Init(
  void *argument
)
{
  printf( "\n\n*** HELLO WORLD TEST ***\n" );
  printf( "Hello World\n" );
  printf( "*** END OF HELLO WORLD TEST ***\n" );
  return NULL; //exit( 0 );
}

Below is the Init() function for hello_world_c. The final call to exit() terminates the simulator as expected. *However, if I replace the final call to exit() with a "return NULL" statement, the simulator also exits. Why does the scheduler not pick up the idle task and keep the simulator running?*

rtems_task Init(
  rtems_task_argument ignored
)
{
  rtems_status_code status;
  printf( "\n\n*** HELLO WORLD TEST ***\n" );
  printf( "Hello World\n" );
  printf( "*** END OF HELLO WORLD TEST ***\n" );
  return; //exit( 0 );
}

Note that the return type of the Init() function, rtems_task, is defined as void in tasks.h, hence the return statement with no argument.

/**
 *  The following defines the "return type" of an RTEMS task.
 */
typedef void rtems_task;

-keith



More information about the users mailing list