<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
   <TITLE>Linux Threads Home Page: Are Linux threads the same as other implementation?</TITLE>
   <META NAME="GENERATOR" CONTENT="Mozilla/3.0Gold (WinNT; U) [Netscape]">
</HEAD>
<BODY BACKGROUND="GraySea.gif">

<P><FONT SIZE=+3>Are Linux threads the same as other implementations?</FONT></P>

<UL>
<P>No. They are better -- while mostly keeping the same API. As stated
above, most multithreaded OSs define a thread <B>separately</B> from processes.
Linus Torvalds has defined that a thread is a &quot;context of execution&quot;
(COE). This means that only one process/thread table and one scheduler
is needed. Also the scheduler has been optomized so that the switching
time for threads vs. tasks varies little--about 1.7us (threads) and 1.8us
(fork) on a 75MHz Pentium.</P>

<P>Traditionally, a thread was just a CPU (and some other minimal state)
state with the process containing the remains (data, stack, I/O, signals).
This would lend itself to very fast switching but would cause basic problems
(e.g. what do &quot;fork()&quot; or &quot;execve()&quot; calls mean when
executed by a thread?).</P>

<P>Consider Linux threads as a superset of this functionality: they still
can switch fast and share process parts, but they can also identify what
parts get shared and have no problems with execve() calls. There are four
<A HREF="./CloneFlags.html">flags</A>
that determine the level of sharing: </P>

<CENTER><TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 >
<CAPTION>
<P><FONT SIZE=+2>Clone Flag Values</FONT></P>
</CAPTION>

<TR>
<TD><TT>#define</TT></TD>

<TD><TT>CLONE_VM</TT></TD>

<TD><TT>0x00000100</TT></TD>
</TR>

<TR>
<TD><TT>#define</TT></TD>

<TD><TT>CLONE_FS</TT></TD>

<TD><TT>0x00000200</TT></TD>
</TR>

<TR>
<TD><TT>#define</TT></TD>

<TD><TT>CLONE_FILES</TT></TD>

<TD><TT>0x00000400</TT></TD>
</TR>

<TR>
<TD><TT>#define</TT></TD>

<TD><TT>CLONE_SIGHAND</TT></TD>

<TD><TT>0x00000800</TT></TD>
</TR>

<TR>
<TD><TT>#define</TT></TD>

<TD><TT>CLONE_PID</TT></TD>

<TD><TT>/* <A HREF="./CloneFlags.html">not
fully implemented</A> */</TT></TD>
</TR>
</TABLE></CENTER>

<P>There has been a lot of talk about &quot;clone()&quot;. The system call
(please note: <I>&quot;l<B>ow level&quot;</B></I>) clone() is an extension
to fork(). In fact, clone(0) == fork(). But with the above #define's, any
combination of the VM, filesystem, I/O, signal handlers and process ID
may be shared.</P>
</UL>

<P>
<HR SIZE=4 WIDTH="100%"></P>

<CENTER><TABLE CELLSPACING=0 CELLPADDING=0 >
<TR>
<TD>
<CENTER><P><A HREF="./Support.html"><IMG SRC="ArrowLeft.gif" ALT="[Left Arrow]" BORDER=0 HEIGHT=40 WIDTH=40></A></P></CENTER>
</TD>

<TD>
<CENTER><P><A HREF="./index.html"><IMG SRC="House.gif" ALT="[Home]" BORDER=0 HEIGHT=40 WIDTH=40></A></P></CENTER>
</TD>

<TD>
<CENTER><P><A HREF="./Dictionary.html"><IMG SRC="BookSearch.gif" ALT="[Book Search]" BORDER=0 HEIGHT=40 WIDTH=40></A></P></CENTER>
</TD>

<TD>
<CENTER><P><A HREF="mailto:walton@oclc.org"><IMG SRC="MailBox.gif" ALT="[Mailbox]" BORDER=0 HEIGHT=40 WIDTH=40></A></P></CENTER>
</TD>

<TD>
<CENTER><P><A HREF="./Reentrancy.html"><IMG SRC="ArrowRight.gif" ALT="[Right Arrow]" BORDER=0 HEIGHT=40 WIDTH=40></A></P></CENTER>
</TD>
</TR>

<TR>
<TD><A HREF="./Support.html">[Previous
Page]</A></TD>

<TD><A HREF="./index.html">[First
Page]</A></TD>

<TD><A HREF="./Dictionary.html">[Dictionary]</A></TD>

<TD><A HREF="mailto:walton@oclc.org">[Email Author]</A></TD>

<TD><A HREF="./Reentrancy.html">[Next
Page]</A></TD>
</TR>
</TABLE></CENTER>

</BODY>
</HTML>
