Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing arguments to pthread_create - invalid conversion from void(*)() to void(*)(void*)
    primarykey
    data
    text
    <p>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:</p> <p>int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);</p> <p>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] }; ^</p> <p>Here is the code:</p> <pre><code>#include &lt;ctype.h&gt; #include &lt;unistd.h&gt; #include &lt;sys/times.h&gt; #include &lt;pthread.h&gt; #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&lt;SLOTX; slot++){ printf("Starting new frame\n"); for(cycle = 0; cycle&lt;CYCLEX; cycle++){ for(i = 0; i&lt;NUM_THREADS; i++){ rc = pthread_create(&amp;thread[i], NULL, (*ttable[slot][cycle]), *(void*)j); } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload