linux 多线程之设置线程的属性
pthread_attr_init(&pthread_attr);
param.sched_priority = 90;
pthread_attr_setschedpolicy(&pthread_attr, SCHED_FIFO);
pthread_attr_setschedparam(&pthread_attr, ¶m);
pthread_attr_setinheritsched(&pthread_attr, PTHREAD_EXPLICIT_SCHED);
pthread_create(&pid, &pthread_attr, start_ain_source_thread, NULL);
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#define NDEBUG
#include <assert.h>
typedef struct aiodev_attr
{
int frame_sample_num;
int chn_num;
int clk_source;
} aiodev_attr_s;
static int running = 1;
static void* start_ain_source_thread(void *p_arg)
{
while(running)
{
printf(" start_ain_source_thread start_ain_source_thread \r\n");
usleep(100*1000);
}
return 0;
}
int main()
{
pthread_attr_t pthread_attr;
struct sched_param param;
pthread_t pid;
// init policy;
pthread_attr_init(&pthread_attr);
param.sched_priority = 90;
pthread_attr_setschedpolicy(&pthread_attr, SCHED_FIFO);
pthread_attr_setschedparam(&pthread_attr, ¶m);
pthread_attr_setinheritsched(&pthread_attr, PTHREAD_EXPLICIT_SCHED);
pthread_create(&pid, &pthread_attr, start_ain_source_thread, NULL);
while( 'x' != getchar() )
{
usleep(100000);
}
running = 0;
pthread_join(pid, 0);
return 0;
}