Changeset 674b714 in rtems-docs


Ignore:
Timestamp:
Nov 22, 2017, 12:42:18 PM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
b2c766b
Parents:
97c51c8
git-author:
Sebastian Huber <sebastian.huber@…> (11/22/17 12:42:18)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/24/17 05:56:51)
Message:

c-user: Document global construction

Close #3243.

Location:
c-user
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c-user/fatal_error.rst

    r97c51c8 r674b714  
    245245    error.
    246246
    247 INTERNAL_ERROR_POSIX_INIT_THREAD_ENTRY_IS_NULL (27)
    248     A POSIX initialization thread entry function is NULL.  This fatal error may
    249     occur during system initialization.  It is an application configuration
    250     error.
    251 
    252247INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK (28)
    253248    A deadlock was detected during a thread queue enqueue operation.
  • c-user/initialization.rst

    r97c51c8 r674b714  
    279279this table, please refer to the chapter :ref:`Configuring a System`.
    280280
     281Global Construction
     282-------------------
     283
     284The global construction is carried out by the first Classic API initialization
     285task (first is defined by index zero in the Classic API initialization task
     286configuration table).  If no Classic API initialization task exists, then it is
     287carried out by the first POSIX API initialization thread.  If no initialization
     288task or thread exists, then no global construction is performed, see for
     289example :ref:`Specify Idle Task Performs Application Initialization`.  The
     290Classic API task or POSIX API thread which carries out global construction is
     291called the main thread.
     292
     293Global construction runs before the entry function of the main thread.  The
     294configuration of the main thread must take the global construction into
     295account.  In particular, the main thread stack size, priority, attributes and
     296initial modes must be set accordingly.  Thread-local objects and POSIX key
     297values created during global construction are accessible by the main thread.
     298If other initialization tasks are configured, and one of them has a higher
     299priority than the main thread and the main thread is preemptible, this task
     300executes before the global construction.  In case the main thread blocks during
     301global construction, then other tasks may run.  In SMP configurations, other
     302initialization tasks may run in parallel with global construction.  Tasks
     303created during global construction may preempt the main thread or run in
     304parallel in SMP configurations.  All RTEMS services allowed in task context are
     305allowed during global construction.
     306
     307Global constructors are C++ global object constructors or functions with the
     308constructor attribute.  For example, the following test program
     309
     310.. code-block:: c
     311
     312    #include <stdio.h>
     313    #include <assert.h>
     314
     315    class A {
     316      public:
     317        A()
     318        {
     319          puts( "A:A()" );
     320        }
     321    };
     322
     323    static A a;
     324
     325    static thread_local int i;
     326
     327    static thread_local int j;
     328
     329    static __attribute__(( __constructor__ )) void b( void )
     330    {
     331      i = 1;
     332      puts( "b()" );
     333    }
     334
     335    static __attribute__(( __constructor__( 1000 ) )) void c( void )
     336    {
     337      puts( "c()" );
     338    }
     339
     340    int main( void )
     341    {
     342      assert( i == 1 );
     343      assert( j == 0 );
     344      return 0;
     345    }
     346
     347should output:
     348
     349.. code-block:: shell
     350
     351    c()
     352    b()
     353    A:A()
     354
    281355Directives
    282356==========
Note: See TracChangeset for help on using the changeset viewer.