?? new_thread.c
字號:
/* * Written by Der Herr Hofrat, der.herr@hofr.at * (C) 2002 FSMLabs * License: GPL Version 2 *//* * Note: you *MUST* patch schedulers/rtl_sched.c first befor this example works * if run without patching rtl_sched.c the box will probably hard lock up if * you try it a few times ;) */#include <rtl.h>#include <time.h>#include <pthread.h>/* The new threads pthread_t must be in global context */static pthread_t thread1,new_thread;static int new_thread_created=0;void * new_routine(void *arg){ struct sched_param p; p . sched_priority = 1; pthread_setschedparam (pthread_self(), SCHED_FIFO, &p); pthread_make_periodic_np (pthread_self(), gethrtime(), 800000000); while (1) { pthread_wait_np (); rtl_printf("new thread; my arg is %x\n", (unsigned) arg); } return 0;}void * start_routine(void *arg){ int ret; struct sched_param p; pthread_attr_t new_attr; p . sched_priority = 1; pthread_setschedparam (pthread_self(), SCHED_FIFO, &p); pthread_make_periodic_np (pthread_self(), gethrtime(), 500000000); /* for threads created from rt-context the attribute structure * must be initialized and passed to pthread_create_np */ pthread_attr_init(&new_attr); ret=pthread_create(&new_thread,&new_attr,new_routine, (void *)66); /* check if the create was successfull befor doing anything with * the new thread */ if(ret == EAGAIN){ rtl_printf("pthread_create failed\n"); } else{ rtl_printf("pthread_create success (return = %d)\n",ret); new_thread_created=1; } while (1) { pthread_wait_np (); rtl_printf("I'm here; my arg is %x\n", (unsigned) arg); } return 0;} int init_module(void){ return pthread_create (&thread1, NULL, start_routine, 0);}void cleanup_module(void){ pthread_delete_np (thread1); /* don't forget to remove the newly created thread */ if(new_thread_created){ pthread_delete_np (new_thread); printk("new thread deleted\n"); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -