Get/Set the pthread scheduling policy in Linux
<p>The code below is a sample provided by the book in my Operating Systems course.
When compiling it I get the error shown below it.</p>

<pre><code>#include &lt;pthread.h&gt;
#include &lt;stdio.h&gt;
#define NUM_THREADS 5

int main(int argc, char *argv[])
{
    int i, policy;
    pthread_t tid[NUM_THREADS];
    pthread_attr_t attr;

    pthread_attr_init(&amp;attr);

    if(pthread_attr_getschedpolicy(&amp;attr, &amp;policy) != 0)
        fprintf(stderr, "Unable to get policy.\n");
    else{
        if(policy == SCHED_OTHER)
            printf("SCHED_OTHER\n");
        else if(policy == SCHED_RR)
            printf("SCHED_RR\n");
        else if(policy == SCHED_FIFO)
            printf("SCHED_FIFO\n");
    }

    if(pthread_attr_setschedpolicy(&amp;attr, SCHED_FIFO) != 0)
        fprintf(stderr, "Unable to set policy.\n");
    /* create the threads */
    for(i = 0; i &lt; NUM_THREADS; i++)
        pthread_create(&amp;tid[i], &amp;attr, runner, NULL);
    /* now join on each thread */
    for(i = 0; i &lt; NUM_THREADS; i++)
        pthread_join(tid[i], NULL);
}

/* Each thread will begin control in this function */
void *runner(void *param)
{
    /* do some work... */

    pthread_exit(0);
}
</code></pre>

<p>I compiled it using this command...</p>

<pre><code>gcc linux_scheduling.c -o scheduling
</code></pre>

<p>However, I get this error.</p>

<blockquote>
<pre><code>linux_scheduling.c:32:34: error: 'runner' undeclared (first use in this function)   
pthread_create(&amp;tid[i], &amp;attr, runner, NULL);
                               ^
linux_scheduling.c:32:34: note: each undeclared identifier is report only once for each function it appears in
</code></pre>
</blockquote>

<p>I tried adding <code>-pthread</code>:</p>

<pre><code>gcc linux_scheduling.c -o scheduling -pthread
</code></pre>

<p>but the error remains.</p>

<p>Thanks for your help!</p>