xiaoxiang781216 commented on issue #4612:
URL: 
https://github.com/apache/incubator-nuttx/issues/4612#issuecomment-927301640


   > The main thread of a task should be able to call pthread_exit(), of 
course, calling pthread_self() first. Certainly this behavior is not prohibited 
by the specifications at OpenGroup.org and there are several posts that 
specifically claim that this is possible. See for example: 
https://programmer.help/blogs/the-use-of-pthread-exit-in-main-thread.html
   > 
   > In this case, the main thread of the process/task group will terminate, 
but the process/task group will persist and other threads will continue 
running. I believe that calling pthread_exit() from the main thread will 
currently lead to an assertion or crash due to the different forms of the main 
and pthread TCBs
   
   Yes, this is major reason why we can't handle main thread and pthread 
equally. The best fix could be unify two tcb struct into one and:
   
   1. Move main thread specific data to task_info
   2. Move pthread specific data to tls_info
   
   > and the fact that global data is retained in the main thread's stack.
   > 
   
   It's fixed by patch: https://github.com/apache/incubator-nuttx/pull/3992
   
   > Similarly, a pthread should be able to call exit() and terminate the 
entire process/ See for example 
https://www.informit.com/articles/article.aspx?p=2085690&seqNum=5. In fact, 
this is often the case when exit() is called from a signal handler in a 
multi-threaded task because we never know for sure which thread the signal 
handler will run on.
   > 
   > Again, a crash would be likely due to the same reasoning.
   
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to