Is there a difference in how threads work in Linux vs Unix vs Solaris

linux, solaris, unix

Solution

The original Unix does not use threads for multiprogramming. An article from 1987 comparing the Mach and Unix kernel states that "neither Unix System V nor 4.3 BSD provide a way to manage more than one thread of control within an address space".

Modern Unix clones adhere to the POSIX Threads specification. The POSIX Threads standard only appeared in 1995. The underlying implementation in Linux is based on the clone() and futex() system calls, which are implemented by the kernel. The clone() system call creates a new lightweight process that can share a memory space with its child. So, for example, the pthread_create() library call internally calls the clone() system call. The futex() system call implements a synchronization primitive that can be used for creating larger synchronization operations, like mutexes, semaphores, etc. So, for example, pthread_mutex_lock() will call futex() internally.

Using POSIX terminology, Linux implementation model is a "kernel-thread model", also known as 1:1 model, where 1 kernel lightweight process is used for 1 user visible thread.

Linux also had different threading implementations over time. More description about threading support in Linux in pthreads(7), clone(2) and futex(2) manual pages.

Other implementations may be completely different and still implement the POSIX threads API. FreeBSD used a M:N implementation, or "hybrid model", where an user visible thread could be managed either by the kernel, or by a user space library. See the kse(2) manual page for a complete description. I have once traced the current 1:1 FreeBSD threading implementation to an article in kerneltrap:

http://web.archive.org/web/20110512021159/http://kerneltrap.org/node/624

OpenSolaris doesn't seem to describe its own threading implementation on man pages. I could find instead a document comparing the OpenSolaris kernel with Linux 2.6 and Windows Vista. There, a main difference between the Linux and OpenSolaris implementation is that in Linux, each process is a lightweight process, unifying threads and processes, while in OpenSolaris one process contains multiple lightweight processes, in practice separating in the kernel the process from the kernel thread.

References:

http://en.wikipedia.org/wiki/Thread_(computing)

http://en.wikipedia.org/wiki/POSIX_Threads

http://repository.cmu.edu/cgi/viewcontent.cgi?article=2728&context=compsci

http://man7.org/linux/man-pages/man7/pthreads.7.html

http://man7.org/linux/man-pages/man2/clone.2.html

http://man7.org/linux/man-pages/man2/futex.2.html

http://pubs.opengroup.org/onlinepubs/7908799/xsh/threads.html

http://www.freebsd.org/cgi/man.cgi?query=kse&apropos=0&sektion=0&manpath=FreeBSD+7.2-RELEASE&format=html

http://web.archive.org/web/20110512021159/http://kerneltrap.org/node/624

http://www.unix.com/man-page/opensolaris/5/threads/

http://www.infoq.com/articles/kernel-comparison-unix-zhu

Problem

I'm just curious to if there is any difference to how threads work in the different flavors of Unix. In particular Linux, Solaris and the original Unix Any thoughts?

Original source