tst-stack2.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
  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. /* Test whether it is possible to create a thread with PTHREAD_STACK_MIN
  16. stack size. */
  17. #include <pthread.h>
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <limits.h>
  21. static int seen;
  22. static void *
  23. tf (void *p)
  24. {
  25. ++seen;
  26. return NULL;
  27. }
  28. static int
  29. do_test (void)
  30. {
  31. pthread_attr_t attr;
  32. pthread_attr_init (&attr);
  33. int result = 0;
  34. int res = pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
  35. if (res)
  36. {
  37. printf ("pthread_attr_setstacksize failed %d\n", res);
  38. result = 1;
  39. }
  40. /* Create the thread. */
  41. pthread_t th;
  42. res = pthread_create (&th, &attr, tf, NULL);
  43. if (res)
  44. {
  45. printf ("pthread_create failed %d\n", res);
  46. result = 1;
  47. }
  48. else
  49. {
  50. res = pthread_join (th, NULL);
  51. if (res)
  52. {
  53. printf ("pthread_join failed %d\n", res);
  54. result = 1;
  55. }
  56. }
  57. if (seen != 1)
  58. {
  59. printf ("seen %d != 1\n", seen);
  60. result = 1;
  61. }
  62. return result;
  63. }
  64. #define TEST_FUNCTION do_test ()
  65. #include "../test-skeleton.c"