I am writing a small simple program that implements a cyclic executive schedule using pthreads. I first wrote the program without pthreads and am now trying to correctly pass parameters into pthread_create. I know that the args are:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
but sending the threads to ttable(the schedule) is giving me difficulty. Now that I am using threads I have added the void* x parameter even though I am not using it (is this parameter required?) I have tried leaving the schedule with no parameters and passing NULL in as the last arg of pthread_create as well. My error is currently: error: invalid conversion from 'void ( * )( )’ to ‘void ( * )(void*)’ [-fpermissive] }; ^
Here is the code:
#include <ctype.h>
#include <unistd.h>
#include <sys/times.h>
#include <pthread.h>
#define SLOTX 6
#define CYCLEX 4
#define SLOT_T 1000 //1 second slot time
#define NUM_THREADS 3
int tps;
int i;
int j;
int rc;
int cycle = 0;
int slot = 0;
struct tms n;
void one(void* x){
printf("Task 1 running\n");
sleep(1);
}
void two(void* x){
printf("Task 2 running\n");
sleep(1);
}
void three(void* x){
printf("Task 3 running\n");
sleep(1);
}
void burn(void* x){
printf("Burn cycle\n");
sleep(1);
}
void (*ttable[SLOTX][CYCLEX])(void* x) = {
{one, one, two, two},
{three, three, three, three},
{two, two, one, one},
{burn, two, two, burn},
{three, three, three, three},
{one, one, two, two}
};
main(){
tps = sysconf(_SC_CLK_TCK);
pthread_t thread[NUM_THREADS];
printf("clock ticks/sec = %d\n\n", tps);
while(1){
printf("Starting new hyperperiod\n");
for(slot = 0; slot<SLOTX; slot++){
printf("Starting new frame\n");
for(cycle = 0; cycle<CYCLEX; cycle++){
for(i = 0; i<NUM_THREADS; i++){
rc = pthread_create(&thread[i], NULL, (*ttable[slot][cycle]), *(void*)j);
}
}
}
}
}
void one(void*)
instead ofvoid one()
etc or I think you need to change(void *x)
to just()
– Justin