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.

  • There's probably someone here who knows this better than me :-), but I don't think System V itself implemented threads. – sourcejedi Jan 1 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 1 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 - web.archive.org/web/20090327002504/http://www.sun.com/software/… – Stephen Harris Jan 2 at 0:45
  • @Tim Your assumptions are wrong. A task_struct represents both processes and threads. – Johan Myréen Jan 2 at 6: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 2 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.