Back to index

glibc  2.9
Defines | Functions | Variables
tst-sched1.c File Reference
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()

Functions

static void * tf (void *a)
int do_test (void)

Variables

static int global

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 97 of file tst-sched1.c.


Function Documentation

int do_test ( void  )

Definition at line 38 of file tst-sched1.c.

{
  pthread_t th;
  pthread_attr_t at;

  if (pthread_attr_init (&at) != 0)
    {
      puts ("attr_init failed");
      return 1;
    }

  if (pthread_attr_setschedpolicy (&at, SCHED_OTHER) != 0)
    {
      puts ("attr_setschedpolicy failed");
      return 1;
    }

  struct sched_param pa;
  if (sched_getparam (getpid (), &pa) != 0)
    {
      puts ("sched_getschedparam failed");
      return 1;
    }

  if (pthread_attr_setschedparam (&at, &pa) != 0)
    {
      puts ("attr_setschedparam failed");
      return 1;
    }

  if (pthread_attr_setinheritsched (&at, PTHREAD_EXPLICIT_SCHED) != 0)
    {
      puts ("attr_setinheritsched failed");
      return 1;
    }

  if (pthread_create (&th, &at, tf, NULL) != 0)
    {
      puts ("create failed");
      return 1;
    }

  int e = pthread_join (th, NULL);
  if (e != 0)
    {
      printf ("join failed: %d\n", e);
      return 1;
    }

  if (global == 0)
    {
      puts ("thread didn't run");
      return 1;
    }

  return 0;
}

Here is the call graph for this function:

static void* tf ( void *  a) [static]

Definition at line 29 of file tst-sched1.c.

{
  global = 1;

  return 0;
}

Variable Documentation

int global [static]

Definition at line 26 of file tst-sched1.c.