test-pthread-create.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright 2011,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* Test whether threads created with `pthread_create' work (bug #32436)
  16. when then main thread is the one that initializes Guile. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include <pthread.h>
  21. #include <stdlib.h>
  22. #include <libguile.h>
  23. static void *
  24. do_something (void *arg)
  25. {
  26. scm_list_copy (scm_make_list (scm_from_int (1234), SCM_BOOL_T));
  27. scm_gc ();
  28. return NULL;
  29. }
  30. static void *
  31. thread (void *arg)
  32. {
  33. scm_with_guile (do_something, NULL);
  34. return NULL;
  35. }
  36. static void *
  37. inner_main (void *data)
  38. {
  39. int i;
  40. pthread_t thr;
  41. do_something (NULL);
  42. for (i = 0; i < 77; i++)
  43. {
  44. pthread_create (&thr, NULL, thread, NULL);
  45. pthread_join (thr, NULL);
  46. }
  47. return NULL;
  48. }
  49. int
  50. main (int argc, char *argv[])
  51. {
  52. scm_with_guile (inner_main, NULL);
  53. return EXIT_SUCCESS;
  54. }