3

In my previous post, about the Linux kernel,

  • the structure task_struct represents threads i.e. light weight processes, but not processes.

  • processes are not represented by any structure, but by groups of threads sharing the same thread group id.

I was wondering how differently or similarly a typical Unix kernel (System V, FreeBSD, ...) implements processes and threads at a high level? Thanks.

Tim
  • 101,790
  • There's probably someone here who knows this better than me :-), but I don't think System V itself implemented threads. – sourcejedi Jan 01 '19 at 14:35
  • If you search for Solaris threads, I think you should be able to find information about Solaris userspace's first attempt using M:N threads, and then giving up and switching to 1:1 threads. In M:N threads, the application sees M threads but the kernel is only providing N threads. The C library is multiplexing them, scheduling when each application thread gets to run on one of the N kernel threads. According to Wikipedia "Solaris" proper is based on System V, but it is also described as merging both lines because SunOS was based on BSD (and presumably influenced Solaris). – sourcejedi Jan 01 '19 at 14:35
  • @sourcejedi With Solaris the answer also changed over time, as hardware changed. So early threading was "green" (userspace many-to-one). As you mention, Sun also looked at a many-to-many model, and then a one-to-one model. There's an old whitepaper which goes into detail - https://web.archive.org/web/20090327002504/http://www.sun.com/software/whitepapers/solaris9/multithread.pdf – Stephen Harris Jan 02 '19 at 00:45
  • @Tim Your assumptions are wrong. A task_struct represents both processes and threads. – Johan Myréen Jan 02 '19 at 06:22
  • If you look at the history of threads in Linux, you'll see there have been multiple implementations in the past, for instance LinixThreads, which is a precursor of the current NPTL implementation. There were also other thread libraries available on Linux, many implementing them in userspace, some of which predate the clone syscall. – filbranden Jan 02 '19 at 09:45
  • For a long time Unixes did not have threads. The argument went like this, MS: we have threads. We need them, because we need a way to wait on multiple events, and createProcess is expensive. Unix: but we can just use select/pole, or if we need concurrency we can use fork. It is faster than your createProcess and safer. MS: yes but we have threads. Eventually Unix added threads, for comparability. And they were a little faster to create than fork. – ctrl-alt-delor Feb 10 '20 at 21:58

0 Answers0