如何不使用pthread_cancel而杀死线程
http://www.cnblogs.com/no7dw/archive/2012/09/27/2705847.html
During the time I use standalone cross compliers to build my system, I find there is NO pthread_cancel in pthread.h (/home/dengwei/standalone-toolchain/sysroot/usr/include/pthread.h).
Shocked by that, but here comes the solution, by using pthread_kill to send a signal , and adding a signal handler :
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
pthread_t pid;
void handle_quit(int signo)
{
printf("in qq handle sig %d \n", signo);
pthread_exit(NULL);
}
void* test(void *arg)
{
signal(SIGQUIT,handle_quit );
for(int i=0;i<100;i++)
{
printf("in pthread test \n");
sleep(1);
}
}
int main(void)
{
printf("begin \n");
pthread_create(&pid, NULL , test, NULL);
sleep(3);
if(pthread_kill(pid, 0)!= ESRCH)
{
printf("thread %d exists!\n", pid);
pthread_kill(pid, SIGQUIT);
// pthread_exit(NULL);//this won't work
printf("after kill\n");
}
sleep(1);
printf("exit in main\n");
}
如何不使用pthread_cancel而杀死线程的更多相关文章
- 线程相关函数(1)-pthread_create(), pthread_join(), pthread_exit(), pthread_cancel() 创建取消线程
一. pthread_create() #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_a ...
- linux下pthread_cancel无法取消线程的原因【转】
转自:http://blog.csdn.net/huangshanchun/article/details/47420961 版权声明:欢迎转载,如有不足之处,恳请斧正. 一个线程可以调用pthrea ...
- linux下pthread_cancel无法取消线程的原因
一个线程能够调用pthread_cancel终止同一进程中的还有一个线程,可是值得强调的是:同一进程的线程间,pthread_cancel向还有一线程发终止信号.系统并不会立即关闭被取消线程,仅仅有在 ...
- python中优雅的杀死线程
上一篇博客中,杀死线程采用的方法是在线程中抛出异常 https://www.cnblogs.com/lucky-heng/p/11986091.html, 这种方法是强制杀死线程,但是如果线程中涉 ...
- python中杀死线程
有时候有这样的需要,在某种情况下,需要在主线程中杀死之前创建的某个线程,可以使用下面的方法,通过调用python内置API,在线程中抛出异常,使线程退出. import threading impor ...
- python主动杀死线程
简介 在一些项目中,为了防止影响主进程都会在执行一些耗时动作时采取多线程的方式,但是在开启线程后往往我们会需要快速的停止某个线程的动作,因此就需要进行强杀线程,下面将介绍两种杀死线程的方式. 直接强杀 ...
- mysql杀死线程
查询 正在执行的事务:SELECT * FROM information_schema.INNODB_TRX 根据这个事务的线程ID(trx_mysql_thread_id): 可以使用mysql命令 ...
- mysql中show processlist过滤和杀死线程
select * from information_schema.processlist where HOST LIKE '%192.168.1.8%'; kill ID列
- 线程取消 (pthread_cancel)
线程取消(pthread_cancel) 基本概念pthread_cancel调用并不等待线程终止,它只提出请求.线程在取消请求(pthread_cancel)发出后会继续运行,直到到达某个取消点(C ...
随机推荐
- Shell 学习笔记之条件语句
条件语句 if # if if condition then command fi # if else if condition then command else command fi # if e ...
- Codeforces Round #355 (Div. 2) C. Vanya and Label 水题
C. Vanya and Label 题目连接: http://www.codeforces.com/contest/677/problem/C Description While walking d ...
- Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路
B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...
- C#高级编程9-第2章 核心C#
C#基础 使用C#命名编译器csc.exe,编译C#程序 变量 变量一般初始化后才能使用 类型判断弱类型var,根据初始值判断类型, 变量作用域,可以访问该代码的区域 类中定义的成员变量和属性,作用在 ...
- LR下监控windows系统资源方法
1. 通过客户端与服务器进行网络测试,保证通信畅通.(测试主机本身) 2. 在运行中输入,service.msc打开系统的服务设置,开启服务器端Windows中的如 ...
- Tasker to answer incoming call by pressing power button
nowadays, the smartphone is getting bigger in size, eg. samsung galaxy note and note 2, sorta big in ...
- php 利用fsockopen GET/POST 提交表单及上传文件
1.GET get.php <?php $host = 'demo.fdipzone.com'; $port = 80; $errno = ''; $errstr = ''; $timeout ...
- java基础知识概要图
- DTO vs. Assembly(转载)
DTO vs. Assembly We probably need to make a strong statement about data transfer objects. Do we like ...
- 如何利用javascript获取表单中select下拉列表中所选中项的值value
1.html代码如下: <html> <head> </head> <body> <form name="form1" id= ...