pthread源代码


posix linux环境下的pthread source 通过查看源代码可以对线程的认识更加深刻 你知道吗?线程的底层实现也是调用clone[创建进程] 故有线程是轻量级的进程
资源截图
代码片段和文件信息
/* Copyright (C) 2002-2013 Free Software Foundation Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper  2002.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not see
   .  */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


#ifndef NEED_SEPARATE_REGISTER_STACK

/* Most architectures have exactly one stack pointer.  Some have more.  */
# define STACK_VARIABLES void *stackaddr = NULL

/* How to pass the values to the ‘create_thread‘ function.  */
# define STACK_VARIABLES_ARGS stackaddr

/* How to declare function which gets there parameters.  */
# define STACK_VARIABLES_PARMS void *stackaddr

/* How to declare allocate_stack.  */
# define ALLOCATE_STACK_PARMS void **stack

/* This is how the function is called.  We do it this way to allow
   other variants of the function to have more parameters.  */
# define ALLOCATE_STACK(attr pd) allocate_stack (attr pd &stackaddr)

#else

/* We need two stacks.  The kernel will place them but we have to tell
   the kernel about the size of the reserved address space.  */
# define STACK_VARIABLES void *stackaddr = NULL; size_t stacksize = 0

/* How to pass the values to the ‘create_thread‘ function.  */
# define STACK_VARIABLES_ARGS stackaddr stacksize

/* How to declare function which gets there parameters.  */
# define STACK_VARIABLES_PARMS void *stackaddr size_t stacksize

/* How to declare allocate_stack.  */
# define ALLOCATE_STACK_PARMS void **stack size_t *stacksize

/* This is how the function is called.  We do it this way to allow
   other variants of the function to have more parameters.  */
# define ALLOCATE_STACK(attr pd) 
  allocate_stack (attr pd &stackaddr &stacksize)

#endif


/* Default alignment of stack.  */
#ifndef STACK_ALIGN
# define STACK_ALIGN __alignof__ (long double)
#endif

/* Default value for minimal stack size after allocating thread
   descriptor and guard.  */
#ifndef MINIMAL_REST_STACK
# define MINIMAL_REST_STACK 4096
#endif


/* Newer kernels have the MAP_STACK flag to indica

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-14 18:44  nptl
     文件        2545  2013-11-14 16:43  nptlANNOUNCE
     文件          54  2013-11-14 16:43  nptlBanner
     文件      520054  2013-11-14 16:43  nptlChangeLog
     文件         982  2013-11-14 16:43  nptlDESIGN-barrier.txt
     文件        2235  2013-11-14 16:43  nptlDESIGN-condvar.txt
     文件        2731  2013-11-14 16:43  nptlDESIGN-rwlock.txt
     文件         835  2013-11-14 16:43  nptlDESIGN-sem.txt
     文件        3981  2013-11-14 16:43  nptlDESIGN-systemtap-probes.txt
     文件        1286  2013-11-14 16:43  nptlMakeconfig
     文件       24675  2013-11-14 16:43  nptlMakefile
     文件        1038  2013-11-14 16:43  nptlTODO
     文件         588  2013-11-14 16:43  nptlTODO-kernel
     文件         295  2013-11-14 16:43  nptlTODO-testing
     文件        8157  2013-11-14 16:43  nptlVersions
     文件        1450  2013-11-14 16:43  nptlalloca_cutoff.c
     文件       36671  2013-11-14 16:43  nptlallocatestack.c
     文件        2946  2013-11-14 16:43  nptlcancellation.c
     文件        1726  2013-11-14 16:43  nptlcleanup.c
     文件        1788  2013-11-14 16:43  nptlcleanup_compat.c
     文件        2950  2013-11-14 16:43  nptlcleanup_defer.c
     文件        3058  2013-11-14 16:43  nptlcleanup_defer_compat.c
     文件        1032  2013-11-14 16:43  nptlcleanup_routine.c
     文件        2153  2013-11-14 16:43  nptlcond-perf.c
     文件         399  2013-11-14 16:43  nptlconfigure
     文件       13281  2013-11-14 16:43  nptldescr.h
     文件        2179  2013-11-14 16:43  nptleintr.c
     文件          13  2013-11-14 16:43  nptlelision-conf.h
     文件          31  2013-11-14 16:43  nptlerrno-loc.c
     文件        1117  2013-11-14 16:43  nptlevents.c
     文件        7923  2013-11-14 16:43  nptlforward.c
............此处省略928个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)