tst-basic1.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright (C) 2002, 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 pid_t pid;
  20. static void *
  21. tf (void *a)
  22. {
  23. if (getpid () != pid)
  24. {
  25. write (2, "pid mismatch\n", 13);
  26. _exit (1);
  27. }
  28. return a;
  29. }
  30. int
  31. do_test (void)
  32. {
  33. pid = getpid ();
  34. #define N 2
  35. pthread_t t[N];
  36. int i;
  37. for (i = 0; i < N; ++i)
  38. if (pthread_create (&t[i], NULL, tf, (void *) (long int) (i + 1)) != 0)
  39. {
  40. write (2, "create failed\n", 14);
  41. _exit (1);
  42. }
  43. else
  44. printf ("created thread %d\n", i);
  45. for (i = 0; i < N; ++i)
  46. {
  47. void *r;
  48. int e;
  49. if ((e = pthread_join (t[i], &r)) != 0)
  50. {
  51. printf ("join failed: %d\n", e);
  52. _exit (1);
  53. }
  54. else if (r != (void *) (long int) (i + 1))
  55. {
  56. write (2, "result wrong\n", 13);
  57. _exit (1);
  58. }
  59. else
  60. printf ("joined thread %d\n", i);
  61. }
  62. return 0;
  63. }
  64. #define TEST_FUNCTION do_test ()
  65. #include "../test-skeleton.c"