kthread_run【转】
转自:http://blog.csdn.net/zhangxuechao_/article/details/50876397
头文件
include/linux/kthread.h 创建并启动 /**
* kthread_run - create and wake a thread.
* @threadfn: the function to run until signal_pending(current).
* @data: data ptr for @threadfn.
* @namefmt: printf-style name for the thread.
*
* Description: Convenient wrapper for kthread_create() followed by
* wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).
*/
#define kthread_run(threadfn, data, namefmt, ...) \
({ \
struct task_struct *__k \
= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
if (!IS_ERR(__k)) \
wake_up_process(__k); \
__k; \
}) 创建 /**
* kthread_create - create a kthread.
* @threadfn: the function to run until signal_pending(current).
* @data: data ptr for @threadfn.
* @namefmt: printf-style name for the thread.
*
* Description: This helper function creates and names a kernel
* thread. The thread will be stopped: use wake_up_process() to start
* it. See also kthread_run(), kthread_create_on_cpu().
*
* When woken, the thread will run @threadfn() with @data as its
* argument. @threadfn can either call do_exit() directly if it is a
* standalone thread for which noone will call kthread_stop(), or
* return when 'kthread_should_stop()' is true (which means
* kthread_stop() has been called). The return value should be zero
* or a negative error number; it will be passed to kthread_stop().
*
* Returns a task_struct or ERR_PTR(-ENOMEM).
*/
struct task_struct *kthread_create(int (*threadfn)(void *data),
void *data,
const char namefmt[],
...)
{
struct kthread_create_info create;
DECLARE_WORK(work, keventd_create_kthread, &create); create.threadfn = threadfn;
create.data = data;
init_completion(&create.started);
init_completion(&create.done); /*
* The workqueue needs to start up first:
*/
if (!helper_wq)
work.func(work.data);
else {
queue_work(helper_wq, &work);
wait_for_completion(&create.done);
}
if (!IS_ERR(create.result)) {
va_list args;
va_start(args, namefmt);
vsnprintf(create.result->comm, sizeof(create.result->comm),
namefmt, args);
va_end(args);
} return create.result;
}
EXPORT_SYMBOL(kthread_create); 结束 int kthread_stop(struct task_struct *k); 检测 int kthread_should_stop(void); 返回should_stop标志。它用于创建的线程检查结束标志,并决定是否退出 举例 static int hello_init(void)
{
printk(KERN_INFO "Hello, world!\n"); tsk = kthread_run(thread_function, NULL, "mythread%d", );
if (IS_ERR(tsk)) {
printk(KERN_INFO "create kthread failed!\n");
}
else {
printk(KERN_INFO "create ktrhead ok!\n");
}
return ;
} static void hello_exit(void)
{
printk(KERN_INFO "Hello, exit!\n");
if (!IS_ERR(tsk)){
int ret = kthread_stop(tsk);
printk(KERN_INFO "thread function has run %ds\n", ret);
}
} module_init(hello_init);
module_exit(hello_exit);
kthread_run【转】的更多相关文章
- kthread_run
头文件 include/linux/kthread.h 创建并启动 /** * kthread_run - create and wake a thread. * @threadfn: the fun ...
- kernel_thread()和kthread_run()/kthread_create()的根本区别
0 本质区别 kthread_run()调用kthread_create(), kthread_create()加入链表后,有kthreadd()线程读取链表然后再调用kernel_thread()创 ...
- 《Linux内核设计与实现》课本第三章自学笔记——20135203齐岳
<Linux内核设计与实现>课本第三章自学笔记 进程管理 By20135203齐岳 进程 进程:处于执行期的程序.包括代码段和打开的文件.挂起的信号.内核内部数据.处理器状态一个或多个具有 ...
- Linux 内核通知链随笔【中】
关于内核通知链不像Netlink那样,既可以用于内核与用户空间的通信,还能用于内核不同子系统之间的通信,通知链只能用于内核不同子系统之间的通信.那么内核通知链到底是怎么工作的?我们如何才能用好通知链? ...
- devtmpfs文件系统创建设备节点
分类: LINUX 原文地址:devtmpfs文件系统创建设备节点 作者:wangbaolin719 http://blog.chinaunix.net/uid-27097876-id-4334356 ...
- Linux Process Management && Process Scheduling Principle
目录 . 引言 . 进程优先级 . 进程的生命周 . 进程表示 . 进程管理相关的系统调用 . 进程调度 . 完全公平调度类 . 实时调度类 . 调度器增强 . 小结 1. 引言 在多处理器系统中,可 ...
- 20135220谈愈敏Linux Book_3
第3章 进程管理 进程是Unix操作系统抽象概念中最基本的一种,进程管理是操作系统的心脏所在. 3.1 进程 进程:处于执行期的程序以及相关的资源的总称. 线程:在进程中活动的对象,拥有独立的程序计数 ...
- Mtk Ft6306 touch 驱动 .
1.1. MTK Touch 驱动的组成Mtk Touch driver 驱动包括:Mtk platform 虚拟平台设备驱动.Module touch IC 驱动.Input subsys ...
- Linux Communication Mechanism Summarize
目录 . Linux通信机制分类简介 . 控制机制 0x1: 竞态条件 0x2: 临界区 . Inter-Process Communication (IPC) mechanisms: 进程间通信机制 ...
随机推荐
- 返回数据方法DeaCacheCommand,由CRL自动实现
越来越多的人学起了前端,或许部分的初衷仅是它简单易上手以及好找工作,毕竟几年前只会个html和css就能有工作,悄悄告诉泥萌,这也是博主一年前的初衷 还好numpy, scikit-learn都提供了 ...
- Mysql5.7修改默认密码
由于 Mysql5.7的默认密码是随机生成的,所以需要修改成我们自己常用的密码 1.修改 my.ini,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 my ...
- soui中subscribeEvent订阅控件消息与宏订阅注意事项
同一个控件,subscribeEvent与宏定义不能同时响应,优先响应sub 所以,同一个控件的同一个消息,要想在多个地方响应,就必须sub方式订阅
- PHP 实现“贴吧神兽”验证码
最早看到 “贴吧神兽” 验证码是在百度贴吧,吧主防止挖坟贴,放出了究极神兽验证码 例如: 地址:http://tieba.baidu.com/p/3320323440 可以用 PHP + JavaSc ...
- 经典的javascript函数实例,css的. #区别
先贴javascript经典例子代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- 掌握Thinkphp3.2.0----连贯操作
其实在TP中,说起来语句中的各个关键词都被封装成了函数,将各个由关键词演变来的函数连起来就是所谓的连贯操作.只要注意各个函数直接参数传递的区别就可以了. 再者,不是所有的函数都可以进行连贯操作!!!比 ...
- dock-compose 安装
apt-get install python-pip python-dev pip install -U docker-composechmod +x /usr/local/bin/docker-co ...
- Java之内存诊断
Java 内存诊断比较容易, 需要: 1 获取heap dump 2 分析heap dump 1.1 获取dump之1 VM arguments: -XX:+HeapDumpOnOutOfMemory ...
- CMake的一些使用
1. 使用QT加载CMake工程 打开QT,"文件"->"打开文件或项目"->选中CMakeLists.txt文件,出现对话框,单击下一步,点击&q ...
- CentOS7.2 创建本地YUM源和局域网YUM源
1背景 由于开发环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题. 想着搭建个本地/局域网YUM源,方便自己跟同事安装软件. 2环境 [root@min-base ...