vxworks5.5开始支持POSIX线程实时扩展
vxworks本质只包括系统和任务两个概念,线程以任务形式实现。线程不属于任何进程,只属于整个系统,因而pthread在整个系统范围内竞争。
<1>vxworks任务在同一实地址空间运行,无任何保护机制,任何任务可以直接访问其他任务数据,POSIX中进程共享相关函数未实现。
<2>vxworks无用户和组概念,无进程概念。
创建 pthread_create
等待 ptherad_join
退出 pthread_exit
#include<pthread.h>
#include<stdio.h>
#include<errno.h>
#include<unistd.h>
/*线程1*/
void thread1() {
int i=0;
while (1) {
printf("thread1:%d\n", i);
if (i>3)
pthread_exit(0);
i++;
sleep(1);
}
}
/*线程2*/
void thread2() {
int i=0;
while (1) {
printf("thread2:%d\n", i);
if (i>5)
pthread_exit(0);
i++;
sleep(1);
}
}
int taskDemo() {
pthread_t t1, t2;
/*创建线程*/
pthread_create(&t1, NULL, (void *)thread1, NULL);
pthread_create(&t2, NULL, (void *)thread2, NULL);
/*等待线程退出*/
pthread_join(t1, NULL)