QNX 线程 调度策略 优先级 时钟频率 同步
/*
* barrier1.c
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <sys/neutrino.h>
#include <timer.h>
pthread_barrier_t barrier; // barrier synchronization object
void *thread1 (void *not_used)
{
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(),&policy,¶m);
if(policy == SCHED_OTHER)
printf("SCHED_OTHER 1 \n");
if(policy == SCHED_RR);
printf("SCHED_RR 1 \n");
if(policy==SCHED_FIFO)
printf("SCHED_FIFO 1 \n");
if(policy==SCHED_SPORADIC)
printf("SCHED_SPARODIC 1 \n");
setprio(0, 11); //设置线程优先级 越大优先级越高 0 代表当前进程
printf("thread1 priority is %d\n",getprio(0));
time_t now;
time (&now);
printf ("thread1 starting at %s", ctime (&now));
// do the computation
// let's just do a sleep here...
while(1)
{
delay (100);
pthread_barrier_wait (&barrier);
// after this point, all three threads have completed.
time (&now);
printf ("barrier in thread1() done at %s", ctime (&now));
}
}
void *thread2 (void *not_used)
{
//查看线程的调度策略 默认为轮询
int policy;
struct sched_param param;
pthread_getschedparam(pthread_self(),&policy,¶m);
if(policy == SCHED_OTHER)
printf("SCHED_OTHER 2 \n");
if(policy == SCHED_RR);
printf("SCHED_RR 2 \n");
if(policy==SCHED_FIFO)
printf("SCHED_FIFO 2 \n");
if(policy==SCHED_SPORADIC)
printf("SCHED_SPARODIC 1 \n");
setprio(0, 10); //设置线程优先级 越大优先级越高 0 代表当前进程
printf("thread2 priority is %d\n",getprio(0));
time_t now;
time (&now);
printf ("thread2 starting at %s", ctime (&now));
// do the computation
// let's just do a sleep here...
while(1)
{
delay (200);
pthread_barrier_wait (&barrier);
// after this point, all three threads have completed.
time (&now);
printf ("barrier in thread2() done at %s", ctime (&now));
}
}
int main () // ignore arguments
{
pthread_t threadID1,threadID2;
setprio(0, 12); //设置线程优先级 越大优先级越高 0 代表当前进程
printf("Main priority is %d\n",getprio(0));
//CPU 时钟频率
struct _clockperiod timep;
timep.nsec = 10*1000;
timep.fract = 0;
int ErrCode = 0;
ErrCode = ClockPeriod(CLOCK_REALTIME, &timep, NULL, 0);
if(ErrCode!=0)
{
printf( "Error: %s\n", strerror(ErrCode));
}
/****************************************/
int ret = -1;
int timer_interrupt_id = -1;
ret = InitializeTimerInterrupt(0, 300, &timer_interrupt_id); //设置时钟中断,10ms
/*****************************************/
time_t now;
// create a barrier object with a count of 3
pthread_barrier_init (&barrier, NULL, 3);
// start up two threads, thread1 and thread2
pthread_create (&threadID1, 0, thread1, 0);
pthread_create (&threadID2, NULL, thread2, NULL);
// at this point, thread1 and thread2 are running
// now wait for completion
time (&now);
printf ("main() waiting for barrier at %s", ctime (&now));
while(1)
{
InterruptWait(0, NULL);
pthread_barrier_wait (&barrier);
// after this point, all three threads have completed.
time (&now);
printf ("barrier in main() done at %s", ctime (&now));
}
pthread_exit( NULL );
return (EXIT_SUCCESS);
}
QNX 线程 调度策略 优先级 时钟频率 同步的更多相关文章
- Linux 线程调度策略与线程优先级
Linux内核的三种调度策略 SCHED_OTHER 分时调度策略. 它是默认的线程分时调度策略,所有的线程的优先级别都是0,线程的调度是通过分时来完成的.简单地说,如果系统使用这种调度策略,程序将无 ...
- Java多线程——线程的优先级和生命周期
Java多线程——线程的优先级和生命周期 摘要:本文主要介绍了线程的优先级以及线程有哪些生命周期. 部分内容来自以下博客: https://www.cnblogs.com/sunddenly/p/41 ...
- C#夯实基础之多线程三:线程的优先级
一.为什么需要优先级--线程调度的问题 在现实生活中,优先级是一个很常见的现象:在火车站,如果你是孕妇,你是可以走进站中的专门绿色通道的,可以提前上火车以免拥挤:火警119匪警110出警的时候,都是人 ...
- Linux-pthread如何设置线程的优先级
设置线程优先级的函数: int pthread_setschedparam(pthread_t target_thread, int policy, const struct sched_param ...
- inux进程/线程调度策略与 进程优先级
目的: 系统性的认识linux的调度策略(SCHED_OTHER.SCHED_FIFO.SCHED_RR): 实时调度?分时调度? 混搭系统(实时任务+分时任务),怎样调度. linux的调度策略 l ...
- Java并发编程之线程生命周期、守护线程、优先级、关闭和join、sleep、yield、interrupt
Java并发编程中,其中一个难点是对线程生命周期的理解,和多种线程控制方法.线程沟通方法的灵活运用.这些方法和概念之间彼此联系紧密,共同构成了Java并发编程基石之一. Java线程的生命周期 Jav ...
- C#编程 线程,任务和同步(2) 开启线程
创建线程的几种方法: 1 异步委托 创建线程的一种简单方式是定义一个委托,并异步调用它. 委托是方法的类型安全的引用.Delegate类 还支持异步地调用方法.在后台,Delegate类会创建一个执行 ...
- 线程安全、数据同步之 synchronized 与 Lock
本文Demo下载传送门 写在前面 本篇文章讲的东西都是Android开源网络框架NoHttp的核心点,当然线程.多线程.数据安全这是Java中就有的,为了运行快我们用一个Java项目来讲解. 为什么要 ...
- java 22 - 6 多线程之线程调度和设置线程的优先级
线程调度 假如我们的计算机只有一个 CPU,那么 CPU 在某一个时刻只能执行一条指令,线程只有得到 CPU时间片,也就是使用权,才可以执行指令. 那么Java是如何对线程进行调用的呢? 线程有两种调 ...
随机推荐
- Android之drawable state各个属性具体解释
我们在定义一个drawable的时候能够通过xml定义的drawable对象.它使得一个图片能在不同的状态下显示不同的图案,比方一个Button,它有pressed.focused,或者其他状态,通过 ...
- windows 不能在 本地计算机 启动 Apache
可能是Apache 的监听端口与其他软件有冲突,这是新手常犯的一个错误,Windows安装了IIS服务器的同时,又安装Apache服务器,二个服务器软件都监听TCP/IP协议的80端口,于是就有其中的 ...
- Zend Studio 10.6.0汉化教程(图文)
来源于:http://www.pw88.com/teach/bangong/32.html 此汉化方法适用于所有的zend studio版本.整个汉化思路是:在线或者离线官方下载汉化包,本地安装即 ...
- js 实现图片间隔循环轮播以及没有间隔的循环轮播
链接地址:http://blog.sina.com.cn/s/blog_75cf5f32010199dn.html 最近做了个图片循环轮播的功能.就是几张图片不断的循环滚动显示. 感觉这个方法不错所以 ...
- IDEA 中使用Maven Compile 找不到本地 Jar
本文地址:http://www.cnblogs.com/duwei/p/4656410.html 在IDEA 的子 Maven Module 中使用 compile 进行编译, 一开始提示从私有远程仓 ...
- iOS 常用开源代码整理
本文章不定期整理. 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功 ...
- im 编辑命令总结
一. VIM高亮 进入vim后,在普通模式下输入如下命令,开启php代码高亮显示 :syntax enable :source $VIMRUNTIME/syntax/php.vim 二. ...
- Citrix 服务器虚拟化之二 Xenserver加域管理
Citrix 服务器虚拟化之二 Xenserver加域管理 如果要使用多个用户和用户组来管理XenServer服务器,就必须使用 Active Directory 用户账户进行身份验证.XenSe ...
- 用ASP编写购物车代码
网上购物已成为生活的潮流,在网上购物之后,想要随时查看自己已买的东西,想要随时删除或改动某件商品数量,要怎么做呢?以下我就来写代码及释义.先来做用户登陆页面(login.asp): <html& ...
- pthread_detach(pthread_self())
pthread_detach(pthread_self()) 将状态改为unjoinable状态,确保资源的释放.其实简单的说就是在线程函数头加上 pthread_detach(pthread_sel ...