kernel thread 테스트시 system이 hang 걸리는 이유가 궁금합니다.
글쓴이: junee74 / 작성시간: 화, 2011/05/17 - 10:14오전
안녕하세요. 리눅스 초보입니다.
Linux의 Kernel Thread는 보통 Windows에 사용하는 Thread와 틀린점이 많아 개념잡기가 어렵습니다.
다음의 테스트 코드가 왜 system을 먹통으로 만드는지 궁금합니다.
다음과 같이 프로그램을 했는데 system이 hang이 걸려 응답이 없습니다.
다음 코드에 어떠한 오류가 있어 그런지 궁금합니다.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
static int int_value = 1;
static char *char_value = NULL;
module_param(int_value, int , 0);
module_param(char_value, charp, 0);
#define deb_main printk
static DECLARE_WAIT_QUEUE_HEAD(thread_proc_wait);
struct task_struct *my_task;
static int thread_proc(void *unused)
{
DECLARE_WAITQUEUE(wait, current);
int thread_proc_count = 0;
int i;
deb_main("thread start\n");
while(!kthread_should_stop())
{
thread_proc_count++;
deb_main("thread processing %d\n", thread_proc_count);
for(i=0; i<1000; i++) udelay(1000);
}
deb_main("set current state TASK_RUNNING\n");
__set_current_state(TASK_RUNNING);
deb_main("remove wait queue\n");
remove_wait_queue(&thread_proc_wait, &wait);
return 0;
}
static int hello_init(void)
{
printk("Hello, World!!!\n");
printk("int_value=%d, char_value=%s\n", int_value, char_value);
my_task = kthread_create(thread_proc, NULL, "%s", "my_thread");
if(my_task)
{
deb_main("thread start complete\n");
wake_up_process(my_task);
}
deb_main("hello_init finish\n");
return 0;
}
static void hello_exit(void)
{
printk("Goodbye, World!!!\n");
kthread_stop(my_task);
deb_main("hello_exit finish\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("Jade, Lee");
MODULE_DESCRIPTION("Kernel Module");
MODULE_LICENSE("Dual BSD/GPL");Forums:


댓글 달기