对pthread属性创建的任何限制?

时间:2015-12-02 08:07:45

标签: multithreading pthreads scheduling timing

以下程序无法在pthread中分配属性。当我尝试使用SCHED_FIFO以外的其他方法创建pthread_attr_setschedpolicy时,我无法成功设置线程属性。与PTHREAD_SCOPE_SYSTEM范围类似的情况。

当前创建线程有什么问题?

如何在特定时间/事件中安排线程?

#include <stdio.h>
#include <pthread.h>
#include <time.h>
#include <errno.h>

void *process_ND(void *arg);
void *process_PFD(void *arg);
void *process_EICAS(void *arg);
void *process_IO(void *arg);

int main()
{
   pthread_t thread_PFD, thread_EICAS, thread_ND, thread_IO;
   pthread_attr_t attr_PFD, attr_EICAS, attr_ND, attr_IO;

   pthread_attr_init(&attr_PFD);
   pthread_attr_init(&attr_EICAS);
   pthread_attr_init(&attr_ND);
   pthread_attr_init(&attr_IO);

   if( (0 != pthread_attr_setschedpolicy(&attr_PFD, SCHED_FIFO)) ||
       (0 != pthread_attr_setinheritsched(&attr_PFD, PTHREAD_EXPLICIT_SCHED)) ||
       (0 != pthread_attr_setscope(&attr_PFD, PTHREAD_SCOPE_PROCESS)) )
   {
      printf("ERROR.... in setting the pthread Schedule, Policy, Scolpe attributes for PFD\n");//, error_num, strerror(error_num));
   }

   /* Set the EICAS thread attributes as desired */
   if( (0 != pthread_attr_setschedpolicy(&attr_EICAS, SCHED_FIFO)) ||
       (0 != pthread_attr_setinheritsched(&attr_EICAS, PTHREAD_EXPLICIT_SCHED)) ||
       (0 != pthread_attr_setscope(&attr_EICAS, PTHREAD_SCOPE_PROCESS)) )
   {
      printf("ERROR.... in setting the pthread Schedule, Policy, Scolpe attributes for EICAS\n");
   }

   /* Set the ND thread attributes as desired */
   if( (0 != pthread_attr_setinheritsched(&attr_ND, PTHREAD_EXPLICIT_SCHED)) ||
       (0 != pthread_attr_setschedpolicy(&attr_ND, SCHED_FIFO)) ||
       (0 != pthread_attr_setscope(&attr_ND, PTHREAD_SCOPE_PROCESS)) )
   {
      printf("ERROR.... in setting the pthread Schedule, Policy, Scolpe attributes for ND\n");
   }

   /* Set the IO thread attributes as desired */
   if( (0 != pthread_attr_setinheritsched(&attr_IO, PTHREAD_EXPLICIT_SCHED)) ||
       (0 != pthread_attr_setschedpolicy(&attr_IO, SCHED_FIFO)) ||
       (0 != pthread_attr_setscope(&attr_IO, PTHREAD_SCOPE_PROCESS)) )
   {
      printf("ERROR.... in setting the pthread Schedule, Policy, Scolpe attributes for IO\n");
   }

   //threadStatus_PFD = pthread_create(&thread_PFD, &attr_PFD, process_PFD, (void*)(pthread_array_param+0));
   threadStatus_IO = pthread_create(&thread_IO, &attr_IO, process_IO, (void*)NULL);
   threadStatus_PFD = pthread_create(&thread_PFD, &attr_PFD, process_PFD, (void*)NULL);
   threadStatus_ND = pthread_create(&thread_ND, &attr_ND, process_ND, (void*)NULL);
   threadStatus_EICAS = pthread_create(&thread_EICAS, &attr_EICAS, process_EICAS, (void*)NULL);
   printf("Created all the threads\n");
   return 0;
}

void *process_ND(void *arg)
{

}
void *process_PFD(void *arg)
{

}

void *process_EICAS(void *arg)
{

}

void *process_IO(void *arg)
{

}

0 个答案:

没有答案