QNX 多线程 (线程1每隔20ms读取 number;线程2每隔10ms计算一次)
#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#define MAX 10
pthread_t thread[2];
pthread_mutex_t mut;
int number=0,i;
void *thread1()
{
while(1)
{
number=i;
printf ("Thread1: number=%d\n",number);
delay(20);
}
}
void *thread2()
{
for (i = 0; i < MAX*100; i++)
{
delay(10);
}
pthread_exit(NULL);
}
int main()
{
clock_t start,end;
start=clock();
pthread_create(&thread[0], NULL, thread1, NULL);
pthread_create(&thread[1], NULL, thread2, NULL);
pthread_join(thread[0],NULL);
pthread_join(thread[1],NULL);
end=clock();
printf("The time is %lf s!\n",(double)((end-start)/CLOCKS_PER_SEC));
return 0;
}
结果显示:
Thread1: number=0
Thread1: number=1
Thread1: number=3
Thread1: number=5
Thread1: number=7
Thread1: number=9
Thread1: number=11
Thread1: number=12
Thread1: number=14
Thread1: number=16
Thread1: number=18
Thread1: number=20
Thread1: number=22
Thread1: number=23
Thread1: number=25
Thread1: number=27
Thread1: number=29
Thread1: number=31
Thread1: number=33
Thread1: number=34
Thread1: number=36
Thread1: number=38
Thread1: number=40
Thread1: number=42
Thread1: number=44
Thread1: number=45
Thread1: number=47
Thread1: number=49
Thread1: number=51
Thread1: number=53
Thread1: number=55
Thread1: number=56
Thread1: number=58
Thread1: number=60
Thread1: number=62
Thread1: number=64
Thread1: number=66
Thread1: number=67
Thread1: number=69
Thread1: number=71
Thread1: number=73
Thread1: number=75
Thread1: number=77
Thread1: number=78
Thread1: number=80
Thread1: number=82
Thread1: number=84
Thread1: number=86
Thread1: number=88
Thread1: number=89
Thread1: number=91
Thread1: number=93
Thread1: number=95
Thread1: number=97
Thread1: number=99
Thread1: number=100
Thread1: number=102
Thread1: number=104
Thread1: number=106
Thread1: number=108
Thread1: number=110
Thread1: number=111
Thread1: number=113
Thread1: number=115
Thread1: number=117
Thread1: number=119
Thread1: number=121
Thread1: number=122
Thread1: number=124
Thread1: number=126
Thread1: number=128
Thread1: number=130
Thread1: number=132
Thread1: number=133
Thread1: number=135
Thread1: number=137
Thread1: number=139
Thread1: number=141
Thread1: number=143
Thread1: number=144
Thread1: number=146
Thread1: number=148
Thread1: number=150
Thread1: number=152
Thread1: number=154
Thread1: number=155
Thread1: number=157
Thread1: number=159
Thread1: number=161
Thread1: number=163
Thread1: number=165
Thread1: number=166
Thread1: number=168
Thread1: number=170
Thread1: number=172
Thread1: number=174
Thread1: number=176
Thread1: number=177
Thread1: number=179
Thread1: number=181
Thread1: number=183
Thread1: number=185
Thread1: number=187
Thread1: number=188
Thread1: number=190
Thread1: number=192
Thread1: number=194
Thread1: number=196
Thread1: number=198
Thread1: number=199
Thread1: number=201
Thread1: number=203
Thread1: number=205
Thread1: number=207
Thread1: number=209
Thread1: number=210
Thread1: number=212
Thread1: number=214
Thread1: number=216
Thread1: number=218
Thread1: number=220
Thread1: number=221
Thread1: number=223
Thread1: number=225
Thread1: number=227
Thread1: number=229
Thread1: number=231
Thread1: number=232
Thread1: number=234
Thread1: number=236
Thread1: number=238
Thread1: number=240
Thread1: number=242
Thread1: number=243
Thread1: number=245
Thread1: number=247
Thread1: number=249
Thread1: number=251
Thread1: number=253
Thread1: number=254
Thread1: number=256
Thread1: number=258
Thread1: number=260
Thread1: number=262
Thread1: number=264
Thread1: number=265
Thread1: number=267
Thread1: number=269
Thread1: number=271
Thread1: number=273
Thread1: number=275
Thread1: number=276
Thread1: number=278
Thread1: number=280
Thread1: number=282
Thread1: number=284
Thread1: number=286
Thread1: number=287
Thread1: number=289
Thread1: number=291
Thread1: number=293
Thread1: number=295
Thread1: number=297
Thread1: number=298
Thread1: number=300
Thread1: number=302
Thread1: number=304
Thread1: number=306
Thread1: number=308
Thread1: number=309
Thread1: number=311
Thread1: number=313
Thread1: number=315
Thread1: number=317
Thread1: number=319
Thread1: number=320
Thread1: number=322
Thread1: number=324
Thread1: number=326
Thread1: number=328
Thread1: number=330
Thread1: number=331
Thread1: number=333
Thread1: number=335
Thread1: number=337
Thread1: number=339
Thread1: number=341
Thread1: number=342
Thread1: number=344
Thread1: number=346
Thread1: number=348
Thread1: number=350
Thread1: number=352
Thread1: number=353
Thread1: number=355
Thread1: number=357
Thread1: number=359
Thread1: number=361
Thread1: number=363
Thread1: number=364
Thread1: number=366
Thread1: number=368
Thread1: number=370
Thread1: number=372
Thread1: number=374
Thread1: number=375
Thread1: number=377
Thread1: number=379
Thread1: number=381
Thread1: number=383
Thread1: number=385
Thread1: number=386
Thread1: number=388
Thread1: number=390
Thread1: number=392
Thread1: number=394
Thread1: number=396
Thread1: number=397
Thread1: number=399
Thread1: number=401
Thread1: number=403
Thread1: number=405
Thread1: number=407
Thread1: number=408
Thread1: number=410
Thread1: number=412
Thread1: number=414
Thread1: number=416
Thread1: number=418
Thread1: number=419
Thread1: number=421
Thread1: number=423
Thread1: number=425
Thread1: number=427
Thread1: number=429
Thread1: number=430
Thread1: number=432
Thread1: number=434
Thread1: number=436
Thread1: number=438
Thread1: number=440
Thread1: number=441
Thread1: number=443
Thread1: number=445
Thread1: number=447
Thread1: number=449
Thread1: number=451
Thread1: number=452
Thread1: number=454
Thread1: number=456
Thread1: number=458
Thread1: number=460
Thread1: number=462
Thread1: number=463
Thread1: number=465
Thread1: number=467
Thread1: number=469
Thread1: number=471
Thread1: number=473
Thread1: number=474
Thread1: number=476
Thread1: number=478
Thread1: number=480
Thread1: number=482
Thread1: number=484
Thread1: number=485
Thread1: number=487
Thread1: number=489
Thread1: number=491
Thread1: number=493
Thread1: number=495
Thread1: number=496
Thread1: number=498
Thread1: number=500
Thread1: number=502
Thread1: number=504
Thread1: number=506
Thread1: number=507
Thread1: number=509
Thread1: number=511
Thread1: number=513
Thread1: number=515
Thread1: number=517
Thread1: number=518
Thread1: number=520
Thread1: number=522
Thread1: number=524
Thread1: number=526
Thread1: number=528
Thread1: number=529
Thread1: number=531
Thread1: number=533
Thread1: number=535
Thread1: number=537
Thread1: number=539
Thread1: number=540
Thread1: number=542
Thread1: number=544
Thread1: number=546
Thread1: number=548
Thread1: number=550
Thread1: number=551
Thread1: number=553
Thread1: number=555
Thread1: number=557
Thread1: number=559
Thread1: number=561
Thread1: number=562
Thread1: number=564
Thread1: number=566
Thread1: number=568
Thread1: number=570
Thread1: number=572
Thread1: number=573
Thread1: number=575
Thread1: number=577
Thread1: number=579
Thread1: number=581
Thread1: number=583
Thread1: number=584
Thread1: number=586
Thread1: number=588
Thread1: number=590
Thread1: number=592
Thread1: number=594
Thread1: number=595
Thread1: number=597
Thread1: number=599
Thread1: number=601
Thread1: number=603
Thread1: number=605
Thread1: number=606
Thread1: number=608
Thread1: number=610
Thread1: number=612
Thread1: number=614
Thread1: number=616
Thread1: number=617
Thread1: number=619
Thread1: number=621
Thread1: number=623
Thread1: number=625
Thread1: number=627
Thread1: number=628
Thread1: number=630
Thread1: number=632
Thread1: number=634
Thread1: number=636
Thread1: number=638
Thread1: number=639
Thread1: number=641
Thread1: number=643
Thread1: number=645
Thread1: number=647
Thread1: number=649
Thread1: number=650
Thread1: number=652
Thread1: number=654
Thread1: number=656
Thread1: number=658
Thread1: number=660
Thread1: number=661
Thread1: number=663
Thread1: number=665
Thread1: number=667
Thread1: number=669
Thread1: number=671
Thread1: number=672
Thread1: number=674
Thread1: number=676
Thread1: number=678
Thread1: number=680
Thread1: number=682
Thread1: number=683
Thread1: number=685
Thread1: number=687
Thread1: number=689
Thread1: number=691
Thread1: number=693
Thread1: number=694
Thread1: number=696
Thread1: number=698
Thread1: number=700
Thread1: number=702
Thread1: number=704
Thread1: number=705
Thread1: number=707
Thread1: number=709
Thread1: number=711
Thread1: number=713
Thread1: number=715
Thread1: number=716
Thread1: number=718
Thread1: number=720
Thread1: number=722
Thread1: number=724
Thread1: number=726
Thread1: number=727
Thread1: number=729
Thread1: number=731
Thread1: number=733
Thread1: number=735
Thread1: number=737
Thread1: number=738
Thread1: number=740
Thread1: number=742
Thread1: number=744
Thread1: number=746
Thread1: number=748
Thread1: number=749
Thread1: number=751
Thread1: number=753
Thread1: number=755
Thread1: number=757
Thread1: number=759
Thread1: number=760
Thread1: number=762
Thread1: number=764
Thread1: number=766
Thread1: number=768
Thread1: number=770
Thread1: number=771
Thread1: number=773
Thread1: number=775
Thread1: number=777
Thread1: number=779
Thread1: number=781
Thread1: number=782
Thread1: number=784
Thread1: number=786
Thread1: number=788
Thread1: number=790
Thread1: number=792
Thread1: number=793
Thread1: number=795
Thread1: number=797
Thread1: number=799
Thread1: number=801
Thread1: number=803
Thread1: number=804
Thread1: number=806
Thread1: number=808
Thread1: number=810
Thread1: number=812
Thread1: number=814
Thread1: number=815
Thread1: number=817
Thread1: number=819
Thread1: number=821
Thread1: number=823
Thread1: number=825
Thread1: number=826
Thread1: number=828
Thread1: number=830
Thread1: number=832
Thread1: number=834
Thread1: number=836
Thread1: number=837
Thread1: number=839
Thread1: number=841
Thread1: number=843
Thread1: number=845
Thread1: number=847
Thread1: number=848
Thread1: number=850
Thread1: number=852
Thread1: number=854
Thread1: number=856
Thread1: number=857
Thread1: number=859
Thread1: number=861
Thread1: number=863
Thread1: number=865
Thread1: number=867
Thread1: number=868
Thread1: number=870
Thread1: number=872
Thread1: number=874
Thread1: number=876
Thread1: number=878
Thread1: number=879
Thread1: number=881
Thread1: number=883
Thread1: number=885
Thread1: number=887
Thread1: number=889
Thread1: number=890
Thread1: number=892
Thread1: number=894
Thread1: number=896
Thread1: number=898
Thread1: number=900
Thread1: number=901
Thread1: number=903
Thread1: number=905
Thread1: number=907
Thread1: number=909
Thread1: number=911
Thread1: number=912
Thread1: number=914
Thread1: number=916
Thread1: number=918
Thread1: number=920
Thread1: number=922
Thread1: number=923
Thread1: number=925
Thread1: number=927
Thread1: number=929
Thread1: number=931
Thread1: number=933
Thread1: number=935
Thread1: number=936
Thread1: number=938
Thread1: number=940
Thread1: number=942
Thread1: number=944
Thread1: number=946
Thread1: number=947
Thread1: number=949
Thread1: number=951
Thread1: number=953
Thread1: number=955
Thread1: number=957
Thread1: number=958
Thread1: number=960
Thread1: number=962
Thread1: number=964
Thread1: number=966
Thread1: number=968
Thread1: number=969
Thread1: number=971
Thread1: number=973
Thread1: number=975
Thread1: number=977
Thread1: number=979
Thread1: number=980
Thread1: number=982
Thread1: number=984
Thread1: number=986
Thread1: number=988
Thread1: number=990
Thread1: number=991
Thread1: number=993
Thread1: number=995
Thread1: number=997
Thread1: number=999
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
Thread1: number=1000
QNX 多线程 (线程1每隔20ms读取 number;线程2每隔10ms计算一次)的更多相关文章
- (Java多线程系列七)Java内存模型和线程的三大特性
Java内存模型和线程的三大特性 多线程有三大特性:原子性.可见性.有序性 1.Java内存模型 Java内存模型(Java Memory Model ,JMM),决定一个线程对共享变量的写入时,能对 ...
- java 多线程 集合的包装方法Collections.synchronizedXXXXX;线程安全的集合类:Java.util.concurrent.ConcurrentXXX;java.util.concurrent.CopyOnWriteXXXX
问题:ArrayList 等线程不安全 当多线程并发修改一个集合数据时,可能同一个下标位置被覆盖. 示例代码: 一个List,我们创建10个线程,每个线程往这个List中添加1000条数据,结果往往 ...
- Java多线程系列--“基础篇”09之 interrupt()和线程终止方式
概要 本章,会对线程的interrupt()中断和终止方式进行介绍.涉及到的内容包括:1. interrupt()说明2. 终止线程的方式2.1 终止处于“阻塞状态”的线程2.2 终止处于“运行状态” ...
- Java多线程初学者指南(7):向线程传递数据的三种方法
在传统的同步开发模式下,当我们调用一个函数时,通过这个函数的参数将数据传入,并通过这个函数的返回值来返回最终的计算结果.但在多线程的异步开发模式下,数据的传递和返回和同步开发模式有很大的区别.由于线程 ...
- 重新想象 Windows 8 Store Apps (42) - 多线程之线程池: 延迟执行, 周期执行, 在线程池中找一个线程去执行指定的方法
[源码下载] 重新想象 Windows 8 Store Apps (42) - 多线程之线程池: 延迟执行, 周期执行, 在线程池中找一个线程去执行指定的方法 作者:webabcd 介绍重新想象 Wi ...
- iOS边练边学--多线程介绍、NSThread的简单实用、线程安全以及线程之间的通信
一.iOS中的多线程 多线程的原理(之前多线程这块没好好学,之前对多线程的理解也是错误的,这里更正,好好学习这块) iOS中多线程的实现方案有以下几种 二.NSThread线程类的简单实用(直接上代码 ...
- 从PCI上读取数据 线程和定时器效率
从PCI上读取数据 线程和定时器效率 线程: mythread=AfxBeginThread(StartContinuous,(LPVOID)1,THREAD_PRIORITY_NORMAL,0,CR ...
- JAVA之旅(十四)——静态同步函数的锁是class对象,多线程的单例设计模式,死锁,线程中的通讯以及通讯所带来的安全隐患,等待唤醒机制
JAVA之旅(十四)--静态同步函数的锁是class对象,多线程的单例设计模式,死锁,线程中的通讯以及通讯所带来的安全隐患,等待唤醒机制 JAVA之旅,一路有你,加油! 一.静态同步函数的锁是clas ...
- 26_多线程_第26天(Thread、线程创建、线程池)_讲义
今日内容介绍 1.多线程 2.线程池 01进程概念 A:进程概念 a:进程:进程指正在运行的程序.确切的来说,当一个程序进入内存运行, 即变成一个进程,进程是处于运行过程中的程序,并且具有一定独立功能 ...
随机推荐
- python _thread模块使用
python关于线程管理的有2个类,_thread(在2.x的版本中叫thread)和threading. # encoding: UTF-8 import thread import time ...
- python IDE ulipad配置使用
一直认为认为python自带的编辑器idle实在是太简陋了,连显示行号的功能都没有,也非常不好编辑.找了下windows平台下的Ide,发现ulipad很多人推荐使用,就开始安装了. 首先去官网: h ...
- 平衡工作与生活的艺术——GTD简单介绍
1 开场白 大家好,今天是工作四年来第一次站在部门的分享会议上,所以有讲得不好的地方请大家见谅!而对于今天我想给大家介绍的"GTD工作方法",从2012年接触,认为对工作非常有帮助 ...
- centos安装python gcc sqlite
终端中输入命令:yum install gcc -y yum install python -y yum install sqlite -y
- android switch语句case expressions must be constant expressions
在项目中遇到这样的Exception:case expressions must be constant expressions public class StandingCityActivity e ...
- Spring MVC视图层:thymeleaf vs. JSP
本文对比了同一Spring MVC工程中相同页面(一个订阅表单)分别采用Thymeleaf和JSP(包括JSP.JSTL.Spring tag lib)两种方式的实现. 本文的所有代码来自一个可运行的 ...
- VirtualBox安装及使用说明和虚拟机安装XP系统图文教程
virtualbox是一款开源的虚拟机软件,它能够支持多种操作系统的安装如:Solaris.Windows.DOS.Linux.OS/2 Warp.BSD等系统作为client操作系统,而且最新版本号 ...
- CodeForces Round #173 (282E) - Sausage Maximization 字典树
练习赛的时候这道题死活超时....想到了高位确定后..低位不能对高位产生影响..并且高位要尽可能的为1..就是想不出比较好的方法了实现... 围观大神博客..http://www.cnblogs.co ...
- ModelConvertHelper(将DataTable转换成List<model>)
public class ModelConvertHelper<T> where T : new() { public static IList<T> Conve ...
- 【linux驱动笔记】字符设备驱动相关数据结构与算法
欢迎转载,转载时需保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http:// ...