如何不使用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 ...
随机推荐
- Python文件类型
Python的文件类型分为三种:源代码.字节代码.优化代码. 1. 源代码 Python源代码文件,即py脚本文件,由 python.exe 解释,可在控制台下运行.pyw脚本文件是图形用户接口 ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...
- IO流-复制多极文件夹(递归实现)
package com.io.test; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ...
- ZOJ 2112 Dynamic Rankings (动态第k大,树状数组套主席树)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- C++空类产生哪些成员函数 || C++类可以自动生成的6个成员函数
class Empty { public: Empty(); // 缺省构造函数 Empty( const Empty& ); // 拷贝构造函数 ~Empty ...
- 安装wp8sdk 当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内。
安装wp8sdk 当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内. [1404:0090][2015-06-12T08:00:53]: Error 0x800b0101: Failed ...
- 十大开源ERP点评 献给深水区的中小企业和CIO们
原文地址:http://www.oschina.net/news/58437/top-10-erp-software 如今,企业资源规划(ERP)和客户关系管理(CRM)系统的必要性已经被各种组织和企 ...
- Maven最佳实践:Maven仓库
什么是Maven仓库 在不用Maven的时候,比如说以前我们用Ant构建项目,在项目目录下,往往会看到一个名为/lib的子目录,那里存放着各类第三方依赖jar文 件,如log4j.jar,junit. ...
- python3 urllib.request 网络请求操作
python3 urllib.request 网络请求操作 基本的网络请求示例 ''' Created on 2014年4月22日 @author: dev.keke@gmail.com ''' im ...
- 特殊汉字“𣸭”引发的对于字符集的思考;mysql字符集;sqlalchemy字符集设置;客户端字符集设置;
字符集.字符序的概念与联系 在数据的存储上,MySQL提供了不同的字符集支持.而在数据的对比操作上,则提供了不同的字符序支持. MySQL提供了不同级别的设置,包括server级.database级. ...