Changes in multithreading after Linux version 2.6

Source: Internet
Author: User
Tags posix

The previous time looked at the next apue about multithreading part, said that the Linux multi-threaded is through the clone system call realizes, the verification to this point is not so, the exact version is more than 2.6 is this.

#include <pthread.h>#include<stdio.h>voidPrid (Const Char*name)        {pid_t pid;        pthread_t Tid; PID=Getpid (); Tid=pthread_self (); printf ("%s:pid =%u, Tid = 0x%x\n", Name, (unsignedint) PID, (unsignedint) (TID);}void*foo (void*args) {Prid ("New Thread"); Pthread_exit ((void*)0);}intMainintargcChar Const*argv[])        {pthread_t tid; interr; void*ret; Err= Pthread_create (&tid, NULL, foo, NULL); if(Err! =0) {printf ("Create thread error\n"); } prid ("Main thread"); Pthread_join (Tid,&ret); return 0;}

Compile:

GCC Thread.c-lpthread

Run./a.out, results:

Main thread:pid = 5714, Tid = 0xe7ae4740
New thread:pid = 5714, Tid = 0xe72f4700

You can see that the main thread and the new creation thread get the same process number as the call to Getpid (), which means that it is not implemented by clone. Find the answer when the Netizen said that the cache caused, I can only say that the imagination is very rich. The answer is that Linux 2.6 uses the native POSIX thread library (NPTL) library, instead of the Linuxthreads library, so that the threads under Linux are more thread-like threads.

for detailed differences please see link : http://www.ibm.com/developerworks/cn/linux/l-threading.html

The third edition of Apue already has no such problem. I wanted to know what was changed in the third edition, so I sent an e-mail to the email address [email protected] on the book.

Reply:

I summarized the changes in the preface.


Steve

The Jobs? It ' s a cold joke!

So I decided to post the preface to the third edition, which of course mentions NPTL.

Changes from the Second Edition

One of the biggest changes to the "UNIX specification in posix.1-2008 are the demotion of the streams-related Interfa Ces to obsolescent status. This is the first step before these interfaces was removed entirely in a future version of the. Because of this, I has reluctantly removed the STREAMS content from this edition of the book. Unfortunate change, because the STREAMS interfaces provided a nice contrast to the socket interfaces, and in MA NY ways were more flexible. Admittedly, I am not entirely unbiased if it comes to the STREAMS mechanism, but there is no debating the reduced role I T is playing in current systems:

Linux doesn ' t include STREAMS in its base system, although packages (LiS and OpenSS7) is available to add this Functionali Ty.

Although Solaris includes STREAMS, Solaris 11uses a socket implementation that's not built on top of STREAMS.

Mac OS X doesn ' t include support for STREAMS.

FreeBSD doesn ' t include support for STREAMS (and never did).

So with the removal of the streams-related material, a opportunity exists to replace it with new topics, such as POSIX as Ynchronous I/O.

In the second edition, the Linux version covered is based on the 2.4 version of the source. In this edition, I has updated the version of Linux to 3.2. One of the largest area of differences between these and versions is the threads subsystem. Between Linux 2.4 and Linux 2.6, the threads implementation is changed to the Native POSIX Thread Library (NPTL). NPTL makes threads on Linux behave more like threads on the other systems.

In total, this edition includes more than new interfaces, including interfaces to handle asynchronous I/O, S  Pin locks, barriers, and POSIX semaphores. Most obsolete interfaces is removed, except for a few ubiquitous ones.

Hope to be useful to everyone!

Changes in multithreading after Linux version 2.6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.