aboutsummaryrefslogtreecommitdiff
path: root/linuxthreads/joinrace.c
blob: 0a00355d594debcb7128d424099bd0e1f5683ce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Test case by Permaine Cheung <pcheung@cygnus.com>.  */

#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

void *
sub1 (void *arg)
{
  /* Nothing.  */
  return NULL;
}

int
main (void)
{
  int istatus;
  int policy;
  int cnt;
  pthread_t thread1;
  struct sched_param spresult1, sp1;

  for (cnt = 0; cnt < 100; ++cnt)
    {
      printf ("Round %d\n", cnt);

      pthread_create (&thread1, NULL, &sub1, NULL);
      pthread_join (thread1, NULL);

      istatus = pthread_getschedparam (thread1, &policy, &spresult1);
      if (istatus != ESRCH)
	{
	  printf ("pthread_getschedparam returns: %d\n", istatus);
	  return 1;
	}

      sp1.sched_priority = 0;
      istatus = pthread_setschedparam (thread1, SCHED_OTHER, &sp1);
      if (istatus != ESRCH)
	{
	  printf ("pthread_setschedparam returns: %d\n", istatus);
	  return 2;
	}
    }

  return 0;
}