So, if I follow correctly, we could maybe have one TLS pointer pointing to a struct of pointers, one per each group of globals (one of this groups, would be the set of variables used by getopt()), like:
struct task_globals_s { struct getopt_globals_s *getopt_globals; /* ...others */ }; Then getopt globals would only be allocated once for each task, and only when getopt() is called. Something like that? On Wed, Mar 24, 2021, at 11:24, Gregory Nutt wrote: > > > Of course, I would only call getopt() once. My question was if we use TLS, > > would the memory use scale with the number of threads? Or would this memory > > for getopt() only be allocated on getopt() calls? > > Yes and yes, but the memory use might be as small as a single pointer. > Per task data would be better and exists now in the OS, but we would > have to implement some internal OS api's that libc could use to access it. > > Another thing to consider is that the current per-task-data is protected > and can only be accessed in supervisor mode. That is not a problem for > the FLAT build but might add complication to the PROTECTED build (or at > least more system call overhead). > > KERNEL build mode does not need per-task data at all. It would be > better if the data could just be kept in globals for KERNEL build, just > as with Linux. > > >