线程与信号

1.属性

①每个线程都有自己的信号屏蔽字
②但是信号的处理是进程中所有进程共享的
③进程中的信号是递送到单个线程的,只体现在该进程的pedding上,(谁来响应 就要看从kernel态到usr态 调度的是哪个线程)。首先先拿线程的mask和进程的pedding按位与,在那线程mask和线程pedding按位与
④一个线程给一个线程发信号,体现在该线程的pedding上

2.函数

pthread_sigmask

NAME
pthread_sigmask - examine and change mask of blocked signals

SYNOPSIS
#include <signal.h>

int pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset);

Compile and link with -pthread.

DESCRIPTION
The pthread_sigmask() function is just like sigprocmask(2)

**sigwait **

NAME
sigwait - wait for a signal

SYNOPSIS
#include <signal.h>

 int sigwait(const sigset_t *set, int *sig);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

sigwait(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

DESCRIPTION
The  sigwait()  function  suspends  execution of the calling thread 
until one of the  signals specified in the signal set set becomes
pending

pthread_kill

NAME
pthread_kill - send a signal to a thread

SYNOPSIS
#include <signal.h>

int pthread_kill(pthread_t thread, int sig);

Compile and link with -pthread.

DESCRIPTION
The  pthread_kill()  function  sends  the signal sig to thread, 
a thread in the same process as the caller.

3.线程与fork

当线程调用fork时,就为子进程创建了整个地址空间的副本。
子进程通过继承整个地址空间的副本,还从父进程那里继承了每个互斥量,读写锁和条件变量的状态。如果父进程包含一个以上的线程,子进程在fork返回以后,如果不马上exec的话,就需要清理锁的状态。
未完待续

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值