tst-sched1.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <pthread.h>
  16. #include <stdio.h>
  17. #include <unistd.h>
  18. #include <sys/types.h>
  19. static int global;
  20. static void *
  21. tf (void *a)
  22. {
  23. global = 1;
  24. return 0;
  25. }
  26. int
  27. do_test (void)
  28. {
  29. pthread_t th;
  30. pthread_attr_t at;
  31. if (pthread_attr_init (&at) != 0)
  32. {
  33. puts ("attr_init failed");
  34. return 1;
  35. }
  36. if (pthread_attr_setschedpolicy (&at, SCHED_OTHER) != 0)
  37. {
  38. puts ("attr_setschedpolicy failed");
  39. return 1;
  40. }
  41. struct sched_param pa;
  42. if (sched_getparam (getpid (), &pa) != 0)
  43. {
  44. puts ("sched_getschedparam failed");
  45. return 1;
  46. }
  47. if (pthread_attr_setschedparam (&at, &pa) != 0)
  48. {
  49. puts ("attr_setschedparam failed");
  50. return 1;
  51. }
  52. if (pthread_attr_setinheritsched (&at, PTHREAD_EXPLICIT_SCHED) != 0)
  53. {
  54. puts ("attr_setinheritsched failed");
  55. return 1;
  56. }
  57. if (pthread_create (&th, &at, tf, NULL) != 0)
  58. {
  59. puts ("create failed");
  60. return 1;
  61. }
  62. int e = pthread_join (th, NULL);
  63. if (e != 0)
  64. {
  65. printf ("join failed: %d\n", e);
  66. return 1;
  67. }
  68. if (global == 0)
  69. {
  70. puts ("thread didn't run");
  71. return 1;
  72. }
  73. return 0;
  74. }
  75. #define TEST_FUNCTION do_test ()
  76. #include "../test-skeleton.c"