C++ static constructors and SMP

Chris Johns chrisj at rtems.org
Tue Oct 22 04:30:30 UTC 2013

On 22/10/13 5:30 AM, Sebastian Huber wrote:
> On 10/21/2013 04:59 PM, Chris Johns wrote:
>>> If you only configure one initialization thread, then the other
>>> processors will execute an idle thread.
>> This assumes the primary core which enters the Init thread is always
>> calling the static constructors plus the primary code is calling Init.
>> If a secondary core reaches the lock first it claims it and sets the
>> done flag.
> Once the low-level single threaded initialization is done, there is no
> primary core.  All cores are equal.

Yes and given the thread handler code has no ability to control which 
init task is started it becomes difficult to manage calling the static 
constructors without some form of refactoring.

The RTEMS Init tasks are specific to the RTEMS API and so are not really 
POSIX and clash with the C++ static constructors. They happen to work on 
a single processor system because C++ users never create more than one 
Init task. Personally I would prefer a single task that runs to main and 
this is all we support by default. If RTEMS init tasks are used by a 
user we should not call any static constructors. There is no way we can 
protect the user from this sort of thing happening.


More information about the devel mailing list