为什么这个警告(没有返回,函数返回非void)?

时间:2014-05-25 15:27:07

标签: c linux timer scheduled-tasks scheduler

void *rastertask()
{
    struct sched_param sparm;
    memset(&sparm, 0, sizeof(sparm));
    sparm.sched_priority = 10; /* 0 = lowest, 99 = highest */

    sched_setscheduler(
            0 /* pid, 0 ==> this process */,
            SCHED_RR /* policy */,
            &sparm);

    unsigned int n_loop;
    for(n_loop=0;;n_loop++) {
        struct timespec ts_start, ts_end;
        clock_gettime(CLOCK_REALTIME, &ts_start);

        TASK1(Task2ms_Raster); /* gets called every 2ms */
        if( (n_loop % 5) == 0) {
            TASK2(Task10ms_Raster); /* get called every 5 * 2ms = 10ms */
        }
        if( (n_loop % 50) == 0) {
            TASK3(Task100ms_Raster); /* get called every 50 * 2ms = 100ms */
        }

        if( (n_loop % 250) == 0 ) {
            /* reset loop counter when smallest common
             * multiple of timing grid has been reached */
            n_loop = 0;
        }

        clock_gettime(CLOCK_REALTIME, &ts_end);
        useconds_t const tasks_execution_time = delta_t_us(&ts_start, &ts_end);

        if( tasks_execution_time >= MS_to_US(2) ) {
            /* report an error that tasks took longer than 2ms to execute */
        }

        /* wait for 2ms - task_execution_time so that tasks get called in
         * a close 2ms timing grid */

        else
            usleep( MS_to_US(2) - tasks_execution_time );
    }

}


int main(int argc, char *argv[])
{

               pthread_t thread_id

                if (pthread_create(&thread_id, NULL, &rastertask, NULL)) {
                               perror ("pthread_create");
                               exit (1);
                }

return 0;
}

我在main函数中创建一个线程。在函数中创建了一个调度程序,用于每2毫秒,10毫秒和100毫秒调用任务。 我在void * rastertask()中收到一个警告,因为NO返回,函数返回非void。

1 个答案:

答案 0 :(得分:0)

你承诺返回一个无效指针,但你没有。因此警告。

void*void的返回类型不同。

您可能希望将该函数定义为

void rastertask()

编辑

好,所以你需要将函数定义为void *才能与pthread_create()一起使用。在这种情况下,你需要添加一个return语句,即使它将返回空指针。