下面是我用来测试Vxworks RTP项目中的线程功能的简单代码
#define NUM_THREADS 2
void *PrintHello(void *threadid)
{
long tid = 0;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
return NULL;
}
int main ()
{
int rc;
long t;
pthread_t threads[NUM_THREADS];
pthread_attr_t attr;
pthread_attr_init(&attr);
for(t=0; t<NUM_THREADS; t++)
{
printf("In main: creating thread is : %ld\n", t);
rc = pthread_create(&threads[t], &attr, PrintHello, (void *)t);
if (rc) printf("ERROR; return code from pthread_create() is : %d\n", rc);
//pthread_join(threads[t],NULL);
}
pthread_exit(NULL);
return 0;
}
输出:
In main: creating thread is : 0 ERROR; return code from pthread_create() is : 71
In main: creating thread is : 1 ERROR; return code from pthread_create() is : 71
错误'71'点对应'ENOSYS'错误代码,并且基于搜索发现Vxworks内核中未启用POSIX线程组件。
vxWorks pthreads帖子也与此相关。但我不确定我需要在哪个文件中启用'INCLUDE_POSIX_PTHREAD_SCHEDULER'组件(configRtp.mk/*.cdf文件)。 请提供有关如何将POSIX线程组件添加到内核
的详细步骤