error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type
error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type
我正在尝试开发一个必须执行线程的内核模块。
我在编译模块时遇到错误。
这是模块:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kthread.h> // for threads
static struct task_struct *thread1;
int thread_fn(void) {
while(1) {
printk("Thread_fuction is running ...\n");
msleep(2000);
}
return 0;
}
int thread_init(void) {
char our_thread[8]="thread1";
printk(KERN_INFO "in init");
thread1 = kthread_create(thread_fn,NULL,our_thread);
if((thread1)) {
printk(KERN_INFO "in if");
wake_up_process(thread1);
}
return 0;
}
void thread_cleanup(void) {
int ret;
ret = kthread_stop(thread1);
if(!ret)
printk(KERN_INFO "Thread stopped");
}
MODULE_LICENSE("GPL");
module_init(thread_init);
module_exit(thread_cleanup);
这是错误:
thread.c:25:26: error: passing argument 1 of ‘kthread_create_on_node’
from incompatible pointer type [-Werror=incompatible-pointer-types]
thread1 = kthread_create(thread_fn,NULL,our_thread);
谁能帮我解决这个问题?
在内核源代码中,您可以看到 kthread_create_on_node()
函数的第一个参数类型:int (*threadfn)(void *data)
。但是你的 "threadfn" int thread_fn (void)
粗略地说是 int (*threadfn)(void)
.
类型
因此将 (void)
更改为 (void *data)
。
我正在尝试开发一个必须执行线程的内核模块。
我在编译模块时遇到错误。
这是模块:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kthread.h> // for threads
static struct task_struct *thread1;
int thread_fn(void) {
while(1) {
printk("Thread_fuction is running ...\n");
msleep(2000);
}
return 0;
}
int thread_init(void) {
char our_thread[8]="thread1";
printk(KERN_INFO "in init");
thread1 = kthread_create(thread_fn,NULL,our_thread);
if((thread1)) {
printk(KERN_INFO "in if");
wake_up_process(thread1);
}
return 0;
}
void thread_cleanup(void) {
int ret;
ret = kthread_stop(thread1);
if(!ret)
printk(KERN_INFO "Thread stopped");
}
MODULE_LICENSE("GPL");
module_init(thread_init);
module_exit(thread_cleanup);
这是错误:
thread.c:25:26: error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type [-Werror=incompatible-pointer-types] thread1 = kthread_create(thread_fn,NULL,our_thread);
谁能帮我解决这个问题?
在内核源代码中,您可以看到 kthread_create_on_node()
函数的第一个参数类型:int (*threadfn)(void *data)
。但是你的 "threadfn" int thread_fn (void)
粗略地说是 int (*threadfn)(void)
.
因此将 (void)
更改为 (void *data)
。