如何不使用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 ...
随机推荐
- Codeforces Round #358 (Div. 2) D. Alyona and Strings dp
D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...
- 解决MySQL建立连接问题,快速回收复用TCP的TIME_WAIT
最近同事遇到一个问题,使用python开发的工具在执行的时候无法和MySQL建立连接,其最直接的现象就是满篇的TIME_WAIT,最后通过调整tcp_timestamps参数问题得以解决,再次记录一下 ...
- thrift 安装 make 失败 ar: .libs/ThriftTest_constants.o: No such file or directory
$wget http://mirrors.cnnic.cn/apache/thrift/0.9.1/thrift-0.9.1.tar.gz $tar zxvf thrift-0.9.1.tar.gz ...
- MAIN/autoslb.py · 林語/autoslb - 码云 - 开源中国
MAIN/autoslb.py · 林語/autoslb - 码云 - 开源中国 CloudXNS
- linux系统时间同步,硬件时钟和系统时间同步,时区的设置
1.时间同步(手动): date -s "2015-07-15 22:13:30" hwclock --systohc (表示系统时间同步到硬件时钟) hwclo ...
- BitTorrent Sync 老版本
Sync version 1.4.111 Installer for Windows: BTSync.exe BTSync_x64.exe Installer for OSX: BTSync.dmgG ...
- 11gR2 RAC重新启动后仅仅能起单节点
11gR2 RAC重新启动后仅仅能起单节点 问题背景: 将11gR2 RAC正常部署完毕之后运行两节点重新启动操作发现当中有一个节点的集群资源无法启动,遂再次重新启动该无法启动集群资源的节点,还是不可 ...
- HDU 2222 Keywords Search 【AC自动机模板】
询问有多少个模式串出现在了文本串里面.将模式串插入Trie树中,然后跑一边AC自动机统计一下就哦了. 献上一份模板. #include <cstdio> #include <cstr ...
- MVC使用TempData跨控制器传递信息而无需记住key的名称
通常情况下,使用TempData需要记住key的名称,本篇体验:通过帮助类,实现对TempData的设置.获取.删除. 关于传递信息的类: namespace MvcApplication1.Mode ...
- C#中数据库连接的几种方式
[转载]原文出处http://blog.163.com/ny_lonely/blog/static/188924273201161112931892/ 1.配置文件链接. 利用VS.NET开发平台 ...