xiaoxiang781216 edited a comment on pull request #1922:
URL: https://github.com/apache/incubator-nuttx/pull/1922#issuecomment-705357685


   > @xiaoxiang781216
   > 
   > As long as I checked the latest upstream, I think the issue does not 
relate to SMP.
   
   Yes, it isn't SMP specific. SMP just expose the problem:
   Two CPUs idle thread call nxtask_startup->cxx_initialize at the same time 
which make all global constructors are executed twice.
   But the real issue is that we shouldn't initialize C++ global variables 
inside kernel space at all, because all kernel threads(include idle thread) 
shouldn't use any C++ element at all).
   
   The good side effect with this fix is that the synchronization issue also 
get resolved too, because kernel always create one and only one user task(init) 
and cxx_initialize get called before init's main has the chance to create more 
tasks concurrently.
   
   > Actually the issue happens with lm3s6965-ek:discover configuration.
   > 
   > Also, I noticed that this PR only resolves the issue for kernel thread as 
titled.
   > However, for example, lm3s6965-ek:discover creates 'Telnet daemon' which
   > will call cxx_initialize() in nxtask_startup().
   
   Yes, it is the expected behaviour, please see PR: 
https://github.com/apache/incubator-nuttx/pull/1341 and 
https://github.com/apache/incubator-nuttx-apps/pull/316. The motivation is 
centralize the c++ initialization to common place.
   Of course, all old code which call cxx_initialize manually should be removed 
to avoid the double initialization issue.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to