On Monday, May 6, 2019 11:10 PM Sebastian Huber 
<sebastian.hu...@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

_______________________________________________
users mailing list
users@rtems.org
http://lists.rtems.org/mailman/listinfo/users

Reply via email to