/*
 * thread.c
 *
 *  Created on: Mar 9, 2012
 *      Author: tsx
 */
#include <pthread.h>
#include <stdio.h>


pthread_t task_create(void *(*start_routine)(void *),void *arg,int prio,int stacksize)
{
  struct sched_param sch;
      pthread_attr_t attr;
           pthread_t pt;
                 int ret;

 if(prio!=0&&stacksize!=0)
   {
     pthread_attr_init(&attr);
     //get attr
     pthread_attr_getschedparam(&attr,&sch);
     //set prio
     sch.sched_priority=prio;
     pthread_attr_setschedparam(&attr,&sch);
     //set stack size
     pthread_attr_setstacksize(&attr,stacksize);
     //create thread
     ret=pthread_create(&pt,&attr,start_routine,arg);
   }
 else
   {
     ret=pthread_create(&pt,NULL,start_routine,arg);
   }

 if(ret!=0)
   {
     printf("create thread failed \r\n");
     return -1;
   }
 return pt;
}
