Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In NuttX, C buffered I/O streams are represented with a pre-group array of type FILE.  A stream is accessed from the OS vis the nxched_get_streams() interface (system call).  The streams array is not used by OS and would be another candidate to move into TLS.

In retrospect, this is not such a good idea.  It is not a good idea because the I/O streams are not unique per-thread; they are common across all threads within a task group:  That includes main thread of the group and all child pthreads whose parent, grandparent, of great-grandparent is the main thread.  They all share the same I/O stream array.  As a result, I/O streams must be one per task-group.

This works now because the I/O stream array is a part of the internal OS group structure which is one per task group.  While it would be nice to get the I/O stream around out of the OS, TLS is probably not the right solution to do that.

Re-Entrant getopt()

getopt() is an important C library function used by applications for parsing of task command line parameters.  It is, however, not re-entrant due to the use of global variables:  optarg, opterr, optind, and optopt. There are several, non-standard implementations for a re-entrant version of called getopt_r(), however, these are all wildly different and do not conform to any standard.  Non-standard interfaces are not desirable in NuttX.

...