/* Linuxthreads - a simple clone()-based implementation of Posix */
/* threads for Linux. */
/* Copyright (C) 1996 Xavier Leroy ([email protected]) */
/* */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Library General Public License */
/* as published by the Free Software Foundation; either version 2 */
/* of the License, or (at your option) any later version. */
/* */
/* This program 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 Library General Public License for more details. */
/* Thread creation, initialization, and basic low-level routines */
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include "pthread.h"
#include "internals.h"
#include "spinlock.h"
#include "restart.h"
/* Descriptor of the initial thread */
struct _pthread_descr_struct __pthread_initial_thread = {
&__pthread_initial_thread, /* pthread_descr p_nextlive */
&__pthread_initial_thread, /* pthread_descr p_prevlive */
NULL, /* pthread_descr p_nextwaiting */
PTHREAD_THREADS_MAX, /* pthread_t p_tid */
0, /* int p_pid */
0, /* int p_priority */
&__pthread_handles[0].h_spinlock, /* int * p_spinlock */
0, /* int p_signal */
NULL, /* sigjmp_buf * p_signal_buf */
NULL, /* sigjmp_buf * p_cancel_buf */
0, /* char p_terminated */
0, /* char p_detached */
0, /* char p_exited */
NULL, /* void * p_retval */
0, /* int p_retval */
NULL, /* pthread_descr p_joining */
NULL, /* struct _pthread_cleanup_buffer * p_cleanup */
0, /* char p_cancelstate */
0, /* char p_canceltype */
0, /* char p_canceled */
0, /* int p_errno */
0, /* int p_h_errno */
PTHREAD_START_ARGS_INITIALIZER, /* struct pthread_start_args p_start_args */
{NULL}, /* void ** p_specific[PTHREAD_KEY_1STLEVEL] */
{NULL} /* void * p_libc_specific[_LIBC_TSD_KEY_N] */
};
/* Descriptor of the manager thread; none of this is used but the error
variables and the address for identification. */
struct _pthread_descr_struct __pthread_manager_thread = {
NULL, /* pthread_descr p_nextlive */
NULL, /* pthread_descr p_prevlive */
NULL, /* pthread_descr p_nextwaiting */
0, /* int p_tid */
0, /* int p_pid */
0, /* int p_priority */
NULL, /* int * p_spinlock */
0, /* int p_signal */
NULL, /* sigjmp_buf * p_signal_buf */
NULL, /* sigjmp_buf * p_cancel_buf */
0, /* char p_terminated */
0, /* char p_detached */
0, /* char p_exited */
NULL, /* void * p_retval */
0, /* int p_retval */
NULL, /* pthread_descr p_joining */
NULL, /* struct _pthread_cleanup_buffer * p_cleanup */
0, /* char p_cancelstate */
0, /* char p_canceltype */
0, /* char p_canceled */
0, /* int p_errno */
0, /* int p_h_errno */
PTHREAD_START_ARGS_INITIALIZER, /* struct pthread_start_args p_start_args */
{NULL}, /* void ** p_specific[PTHREAD_KEYS_MAX] */
{NULL} /* void * p_libc_specific[_LIBC_TSD_KEY_N] */
};
/* Pointer to the main thread (the father of the thread manager thread) */
/* Originally, this is the initial thread, but this changes after fork() */
pthread_descr __pthread_main_thread = &__pthread_initial_thread;
/* Limit between the stack of the initial thread (above) and the
stacks of other threads (below). Aligned on a STACK_SIZE boundary. */
char *__pthread_initial_thread_bos = NULL;
/* File descriptor for sending requests to the thread manager. */
/* Initially -1, meaning that the thread manager is not running. */
int __pthread_manager_request = -1;
/* Other end of the pipe for sending requests to the thread manager. */
int __pthread_manager_reader;
/* PID of thread manager */
static int __pthread_manager_pid;
/* Limits of the thread manager stack */
char *__pthread_manager_thread_bos = NULL;
char *__pthread_manager_thread_tos = NULL;
/* For process-wide exit() */
int __pthread_exit_requested = 0;
int __pthread_exit_code = 0;
/* Forward declarations */
static void pthread_exit_process(int retcode, void *arg);
static void pthread_handle_sigcancel(int sig);
/* Initialize the pthread library.
Initialization is split in two functions:
- a constructor function that blocks the PTHREAD_SIG_RESTART signal
(must do this very early, since the program could capture the signal
mask with e.g. sigsetjmp before creating the first thread);
- a regular function called from pthread_create when needed. */
static void pthread_initialize(void) __attribute__((constructor));
static void pthread_initialize(void)
{
struct sigaction sa;
sigset_t mask;
/* If already done (e.g. by a constructor called earlier!), bail out */
if (__pthread_initial_thread_bos != NULL) return;
/* For the initial stack, reserve at least STACK_SIZE bytes of stack
below the current stack address, and align that on a
STACK_SIZE boundary. */
__pthread_initial_thread_bos =
(char *)(((long)CURRENT_STACK_FRAME - 2 * STACK_SIZE) & ~(STACK_SIZE - 1));
/* Update the descriptor for the initial thread. */
__pthread_initial_thread.p_pid = __getpid();
/* If we have special thread_self processing, initialize that for the
main thread now. */
#ifdef INIT_THREAD_SELF
INIT_THREAD_SELF(&__pthread_initial_thread);
#endif
/* Setup signal handlers for the initial thread.
Since signal handlers are shared between threads, these settings
will be inherited by all other threads. */
sa.sa_handler = __pthread_sighandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART; /* does not matter for regular threads, but
better for the thread manager */
sigaction(PTHREAD_SIG_RESTART, &sa, NULL);
sa.sa_handler = pthread_handle_sigcancel;
sa.sa_flags = 0;
sigaction(PTHREAD_SIG_CANCEL, &sa, NULL);
/* Initially, block PTHREAD_SIG_RESTART. Will be unblocked on demand. */
sigemptyset(&mask);
sigaddset(&mask, PTHREAD_SIG_RESTART);
sigprocmask(SIG_BLOCK, &mask, NULL);
/* Register an exit function to kill all other threads. */
/* Do it early so that user-registered atexit functions are called
before pthread_exit_process. */
__on_exit(pthread_exit_process, NULL);
}
static int pthread_initialize_manager(void)
{
int manager_pipe[2];
/* If basic initialization not done yet (e.g. we're called from a
constructor run before our constructor), do it now */
if (__pthread_initial_thread_bos == NULL) pthread_initialize();
/* Setup stack for thread manager */
__pthread_manager_thread_bos = malloc(THREAD_MAN
没有合适的资源?快使用搜索试试~ 我知道了~
glibc-linuxthreads-2.0.6.tar.gz
需积分: 1 0 下载量 171 浏览量
2024-03-04
13:07:57
上传
评论
收藏 85KB GZ 举报
温馨提示
共82个文件
c:20个
h:20个
man:20个
gnu安装包
资源推荐
资源详情
资源评论
收起资源包目录
glibc-linuxthreads-2.0.6.tar.gz (82个子文件)
linuxthreads
condvar.c 6KB
Changes 3KB
cancel.c 4KB
configure 171B
ChangeLog 5KB
Examples
ex5.c 2KB
ex1.c 951B
ex3.c 4KB
Makefile 201B
ex2.c 3KB
ex4.c 3KB
README 6KB
queue.h 2KB
join.c 5KB
man
pthread_key_create.man 5KB
pthread_detach.man 1KB
sem_init.man 4KB
Makefile 795B
troffprepro 1KB
pthread_once.man 912B
pthread_attr_init.man 7KB
pthread_exit.man 937B
pthread_cancel.man 5KB
pthread_self.man 427B
pthread_mutex_init.man 7KB
pthread_create.man 1KB
pthread_join.man 2KB
pthread_setschedparam.man 2KB
pthread_cond_init.man 7KB
pthread_cleanup_push.man 5KB
pthread_condattr_init.man 1KB
pthread_kill_other_threads_np.man 1KB
pthread_atfork.man 2KB
pthread_sigmask.man 4KB
pthread_equal.man 492B
pthread_mutexattr_init.man 3KB
pthread.c 15KB
Makefile 2KB
LICENSE 26KB
errno.c 1KB
weaks.c 5KB
stdio-lock.h 1KB
attr.c 3KB
sysdeps
mips
pt-machine.h 3KB
Implies 16B
sparc
pt-machine.h 2KB
Implies 19B
m68k
pt-machine.h 2KB
Implies 16B
alpha
pt-machine.h 3KB
Implies 16B
unix
sysv
linux
configure 94B
posix_opt.h 3KB
local_lim.h 2KB
Implies 8B
pthread
pthread.h 17KB
Makefile 60B
stdio-lock.h 1KB
cmpxchg
semaphorebits.h 1KB
no-cmpxchg
semaphorebits.h 1KB
libc-lock.h 7KB
stub
pt-machine.h 155B
i386
i586
pt-machine.h 3KB
i686
i486
Implies 19B
powerpc
pt-machine.h 2KB
Implies 16B
ptfork.c 3KB
Banner 33B
FAQ.html 45KB
semaphore.c 7KB
shlib-versions 79B
signals.c 4KB
README.Xfree3.2 9KB
lockfile.c 2KB
specific.c 5KB
manager.c 13KB
semaphore.h 1KB
wrapsyscall.c 5KB
restart.h 2KB
mutex.c 7KB
spinlock.h 1KB
internals.h 10KB
共 82 条
- 1
资源评论
程序员Chino的日记
- 粉丝: 2875
- 资源: 4万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Stability AI 发布 SD3 API:开启人工智能新篇章
- SQL 语言入门篇-最常用 SQL 语句大全
- mysql查询语句汇总.zip
- typora-x64-v0.9.93,windows,64位,markdown工具,文本编辑器
- 基于C语言的neon_osd_Draw ARM Neon加速OSD点阵设计源码
- 目标检测-工地工人安全设备佩戴检测数据集-3500张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本+训练日志
- 运筹学运输问题综合实验的实验报告
- home - 副本.vue
- imageProcess.py
- typora-linux-v0.11.18-amd64,linux,64位,markdown工具,文本编辑器
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功