You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/12/08 20:37:54 UTC

[GitHub] [incubator-nuttx] patacongo edited a comment on issue #2499: getpid should return process id not thread id

patacongo edited a comment on issue #2499:
URL: https://github.com/apache/incubator-nuttx/issues/2499#issuecomment-740986953


   NuttX does not have separate thread IDs.  Process IDs and thread Ids are the same thing.  A pthread ID is just a pid_t that is cast to a pthread_t.
   
   The kind of of threads used in NuttX are sometimes called "heavyweight' threads.  In the Linux 2.4 timeframe, Linux also used heavyweight threads.  pthreads were provide by the old LinuxThreads library.  https://en.wikipedia.org/wiki/LinuxThreads.  It implemented threads using the Linux clone() interface; threads were basically fork's from the parent thread with some special properties -- but each was still a process and each had its own identifying process ID.
   
   With the old Linux threads, pthread_t was also the same as a pid_t.  So the old heavyweight, LinuxThreads were exactly the way that NuttX threads work.  When you did 'ps', threads and process should the same kind of IDs.  gettid() worked basically the same as gitpid() as they do in NuttX.
   
   Around 2006, LinuxThreads was replaced with lightweight, Native POSIX Threads Library (NPTL).  This introduced a hierarchy and a difference in representation so that threads were implemented very differently.  'ps' now shows threads as part of hierarchy and gettid() and gitpid() return very different kinds of values.
   
   Since NuttX follows the old LinuxThreads model, I think it is best to keep the interfaces as they are now (and as they were with LinuxThreads in Linux).
   
   Would there be any advantage of switching to model like NPTL in NuttX?  Perhaps someday.  But for the FLAT and PROTECTED mode there would not be any advantage.  They are already very "lightweight" in the sense that they do not consume very many resources.  I don't think NPTL would improve that very much.  But for the KERNEL build with its huge overhead of mapped pages and MMU page tables, they savings might be substantial.
   
   There is some semantic confusion about what the process ID represents in NuttX.  NuttX uses a "task group" to associate all of the heavyweight threads.  The process ID means two things.  It it the thread ID of the main thread of task group (maintained in the TCB) but it is also the task group ID of the entire collection of associated threads (maintained in the group structure, usually).
   
   group ID is overloaded.  Sorry about that.  NuttX does not support group security as does Linux.  The group ID refers to the "task group", not to the security group.
   


----------------------------------------------------------------
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:
users@infra.apache.org