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是如何对线程进行调用的呢? 线程有两种调 ...
随机推荐
- Eclipse 取消import自动补全具体的类名
有时候,在代码里写了一个JFrame,然后Eclipse就自动添加了import javax.swing.JFrame; 但有时候希望只要import javax.swing.*;就可以了,不希望具体 ...
- STL set的用法
要使用set需要事先引入一个头文件 #include<set> set是一个不允许重复的集合,如果要重复可以使用multiset. 1.set的插入[set.insert();],会返回P ...
- Palindrome(最长回文串manacher算法)O(n)
Palindrome Time Limit:15000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- poj 3176 Cow Bowling(区间dp)
题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...
- STL之Queue(Q)
STL的Queue(数据结构中的队列): 特点:FIFO 先进先出: 自适应容器(即容器适配器) 栈适配器STL queue STL中实现的Queue: 用list来实现queue: queue ...
- VIM: 解决vi/vim中粘贴时行首出现很多缩进和空格的问题
解决vi/vim中粘贴时行首出现很多缩进和空格的问题 http://www.jbxue.com/LINUXjishu/12232.html 由于在secureCRT中会将原来的文本原封不动的按照字符串 ...
- [Swust OJ 763]--校门外的树 Plus(暴力枚举)
题目链接:http://acm.swust.edu.cn/problem/0763/ Time limit(ms): 1000 Memory limit(kb): 65535 西南某科技大学的校门外有 ...
- [Swust OJ 648]--简单字典(数位dp)
题目链接:http://acm.swust.edu.cn/problem/0648/ Time limit(ms): 1000 Memory limit(kb): 65535 有这样一本字典,它每 ...
- IDEA 中使用Maven Compile 找不到本地 Jar
本文地址:http://www.cnblogs.com/duwei/p/4656410.html 在IDEA 的子 Maven Module 中使用 compile 进行编译, 一开始提示从私有远程仓 ...
- Tcl语言笔记之一
1,一个TCL脚本可以包含一个或多个命令.命令之间必须用换行符或分号隔开 2,置换 substitution %set y x+100 // ...