LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1203|回复: 5

有人研究过linuxthread与nptl吗

[复制链接]
发表于 2007-2-26 01:18:24 | 显示全部楼层 |阅读模式
好像手册里没有怎样深入探讨,我想两个都要,该怎样实现?削旧一点的发现版都是两个都有的。
 楼主| 发表于 2007-5-19 23:29:12 | 显示全部楼层
许久的帖子了,还是没人顶。大伙都不会吗?
我顶起来
回复 支持 反对

使用道具 举报

发表于 2007-5-21 14:27:04 | 显示全部楼层
linuxthread 是用进程模拟线程的,不符合 POSIX 标准。
glibc-2.4 以后默认没有 linuxthread 了,但是仍然可以从 gnu ftp 单独下载。把两个都解压后 ./configure --help 看看有没有相关的选项。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-22 18:34:13 | 显示全部楼层
我想两个线程模式共存
回复 支持 反对

使用道具 举报

发表于 2007-5-23 09:32:21 | 显示全部楼层
linuxthreads 需要另外编译:
下载 ftp://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.5.tar.bz2 好像 ftp 上只有 2.5 有 linuxthreads , 2.4/2.6 都没有。
解开进入目录 (build-xxx-xxx-linuxthreads 这类)
设置好 MAKEOPTS 和 install_root ,然后
make PARALLELMFLAGS="${MAKEOPTS}" install_root="${install_root}" install
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-24 00:36:24 | 显示全部楼层
这样只是单纯地编译一个线程的吧?
参考archlinux的glibc编译方案,它是两种线程模式都有的,就是看不明白,帮忙看看吧
# $Id: PKGBUILD,v 1.41 2005/11/23 18:50:25 judd Exp $
# Maintainer: judd <jvinet@zeroflux.org>
pkgname=glibc
pkgver=2.3.5
pkgrel=8
# glibc doesn't release very often, so we often use CVS snapshots to
# stay up-to-date with new features. Snapshots are available from Fedora
_snap=20050524T1606
_hdrver=2.6.12.0
pkgdesc="GNU C Library with NPTL and linuxthreads"
url="http://www.gnu.org/software/libc"
depends=()
source=(ftp://ftp.archlinux.org/other/glibc/glibc-${_snap}.tar.bz2
        ftp://ftp.archlinux.org/other/glibc/glibc-fedora-${_snap}.tar.bz2
        http://ep09.pld-linux.org/~mmazur/linux-libc-headers/linux-libc-headers-${_hdrver}.tar.bz2
        glibc-fedora.patch
        glibc-20050524-20050727.patch
        glibc-zh_TW.patch
        glibc-20050727-20050815.patch
        nscd)
md5sums=('8543c324cdd8c43aea280fa3738f8186' 'ea77b628e06890d36248f2199c3cc1d5'
         'eae2f562afe224ad50f65a6acfb4252c' 'c6768e173970d5ad04de1927baf1306f'
         '29ec3c34425c0460b5d8073b0396b0fd' 'f12227b71659f1dd9b1ef7ee6d630b63'
         '66442b650f6e1c6eb6aef543023972c6' 'b587ee3a70c9b3713099295609afde49')

build() {
  # Kernel Headers
  mkdir -p ${startdir}/pkg/usr/include
  cp -r linux-libc-headers-${_hdrver}/include/linux ${startdir}/pkg/usr/include/linux
  cp -r linux-libc-headers-${_hdrver}/include/asm-i386 ${startdir}/pkg/usr/include/asm
  find ${startdir}/pkg -type d -exec chmod 755 {} \;
  find ${startdir}/pkg -type f -exec chmod 644 {} \;
  echo "" > ${startdir}/pkg/usr/include/linux/config.h
  chown -R root.root ${startdir}/pkg/usr/include

  cd ${startdir}/src/glibc-${_snap}
  patch -E -Np1 -i ${startdir}/src/glibc-fedora.patch || return 1
  patch -Np1 -i ${startdir}/src/glibc-20050524-20050727.patch || return 1
  patch -Np1 -i ${startdir}/src/glibc-zh_TW.patch || return 1
  patch -Np1 -i ${startdir}/src/glibc-20050727-20050815.patch || return 1

  find . -type f -size 0 -o -name "*.orig" -exec rm -f {} \;

  mkdir build-linuxthreads
  cd build-linuxthreads
  if echo '__thread int a;' | gcc -xc - -S -o /dev/null 2>/dev/null; then
    sed -i -e 's/0 [|][|]/1 ||/' ../elf/tst-tls10.h ../linuxthreads/tst-tls1.h
  fi

  AddOns=`cd .. && echo */configure | sed -e 's!/configure!!g;s!\(linuxthreads\|nptl\|rtkaio\)\( \|$\)!!g;s! \+$!!;s! !,!g;s!^!,!;/^,\*$/d'`
  
  
  CFLAGS="${CFLAGS} -DNDEBUG=1" ../configure --prefix=/usr \
    --enable-add-ons=linuxthreads${AddOns} --without-cvs \
    --enable-kernel=2.4.1 --disable-profile \
    --with-headers=$startdir/pkg/usr/include \
    --enable-bind-now --with-tls --without-__thread \
    --build ${CHOST} --host ${CHOST}
   
  make -r CFLAGS="${CFLAGS}" || return 1
  make install_root=${startdir}/pkg install || return 1
  make install_root=${startdir}/pkg localedata/install-locales || return 1
  cd ..
  
  mkdir build-nptl
  cd build-nptl
  CFLAGS="${CFLAGS} -DNDEBUG=1" ../configure --prefix=/usr \
     --enable-add-ons=nptl${AddOns} --without-cvs \
     --enable-kernel=2.6.6 --disable-profile \
     --with-headers=$startdir/pkg/usr/include \
     --enable-bind-now --with-tls --with-__thread \
     --build ${CHOST} --host ${CHOST}
  make -r CFLAGS="${CFLAGS}" || return 1
  
  cd build-nptl
  mkdir -p ${startdir}/pkg/lib/tls/
  libcsofile=`basename ${startdir}/pkg/lib/libc-*.so`
  cp -a libc.so ${startdir}/pkg/lib/tls/${libcsofile}
  ln -sf ${libcsofile} ${startdir}/pkg/lib/tls/`ls libc.so.*`

  libmsofile=`basename ${startdir}/pkg/lib/libm-*.so`
  pushd math > /dev/null
  cp -a libm.so ${startdir}/pkg/lib/tls/${libmsofile}
  ln -sf ${libmsofile} ${startdir}/pkg/lib/tls/`ls libm.so.*`
  popd > /dev/null

  librtsofile=`basename ${startdir}/pkg/lib/librt-*.so`
  pushd rt > /dev/null
  cp -a librt.so ${startdir}/pkg/lib/tls/${librtsofile}
  ln -sf ${librtsofile} ${startdir}/pkg/lib/tls/`ls librt.so.*`
  popd > /dev/null
  
  libthreaddbsofile=`basename ${startdir}/pkg/lib/libthread_db-*.so`
  pushd nptl_db > /dev/null
  cp -a libthread_db.so ${startdir}/pkg/lib/tls/${libthreaddbsofile}
  ln -sf ${libthreaddbsofile} ${startdir}/pkg/lib/tls/`ls libthread_db.so.*`
  popd > /dev/null

  libpthreadsofile=libpthread-${pkgver}.so
  pushd nptl > /dev/null
  cp -a libpthread.so ${startdir}/pkg/lib/tls/${libpthreadsofile}
  ln -sf ${libpthreadsofile} ${startdir}/lib/tls/`ls libpthread.so.*`
  popd > /dev/null
  
  mkdir -p ${startdir}/pkg/usr/lib/nptl
  cp -a libc.a nptl/libpthread.a nptl/libpthread_nonshared.a rt/librt.a \
        ${startdir}/pkg/usr/lib/nptl
  
  for lib in libc libpthread; do
    sed -e "s:/lib/${lib}.so:/lib/tls/${lib}.so:g" \
        -e "s:/usr/lib/${lib}_nonshared.a:/usr/lib/nptl/${lib}_nonshared.a:g" \
        ${startdir}/pkg/usr/lib/${lib}.so \
        > ${startdir}/pkg/usr/lib/nptl/${lib}.so
    chmod 755 ${startdir}/pkg/usr/lib/nptl/${lib}.so
  done

  ln -sf ../librt.so ${startdir}/pkg/usr/lib/nptl/librt.so

  mkdir -p ${startdir}/pkg/nptl ${startdir}/pkg/usr/include/nptl
  make install_root=${startdir}/pkg/nptl install-headers || return 1
  pushd ${startdir}/pkg/nptl/usr/include > /dev/null
  for i in `find . -type f`; do
    if ! [[ -f ${startdir}/pkg/usr/include/${i} ]] \
       || ! cmp -s ${i} ${startdir}/pkg/usr/include/${i}; then
         mkdir -p ${startdir}/pkg/usr/include/nptl/`dirname ${i}`
         cp -a ${i} ${startdir}/pkg/usr/include/nptl/${i}
    fi
  done
  popd > /dev/null
  rm -rf ${startdir}/pkg/nptl

  rm -rf ${startdir}/pkg/etc/ld.so.cache ${startdir}/pkg/etc/localtime
  install -D -m644 ${startdir}/src/glibc-${_snap}/nscd/nscd.conf ${startdir}/pkg/etc/nscd.conf
  install -D -m755 ${startdir}/src/nscd ${startdir}/pkg/etc/rc.d/nscd

  sed -i -e 's/^\tserver-user/#\tserver-user/' ${startdir}/pkg/etc/nscd.conf || return 1
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表