⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new_thread.c

📁 fsmlabs的real time linux的内核
💻 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");	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -