hello.c

来自「gps 源码.GPS工作原理,对开发GPS软件有帮助」· C语言 代码 · 共 36 行

C
36
字号
#include <rtl.h>
#include <time.h>
#include <pthread.h>
pthread_t thread;
//The execution thread is embodied in the hello function
void * hello()
{
	struct sched_param p;
	//assigning the thread with a scheduling priority 1
	p . sched_priority = 1;
	//this sets the scheduler behavior to be SCHED_FIFO for all subsequent execution
	pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);

	while (1) {
		//it blocks all further execution of the thread until the schedular calls it again
		for(i=1;i<=10;i++)
		{
			pthread_wait_np ();
		}
		rtl_printf("hello world");
	}
	return 0;
}
/* This module begins the entire process by creating an execution thread with init_module */

int init_module(void) {
	//it creates the thread
	return pthread_create (&thread, NULL, hello, 0);
}
/* This module ends the entire process by clearing the  execution thread with cleanup_module */

void cleanup_module(void) {
	//it delete the realtime thread
	pthread_delete_np (thread);
}

⌨️ 快捷键说明

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