test-pthread-create.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Copyright (C) 2011 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * 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. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. /* Test whether threads created with `pthread_create' work (bug #32436)
  19. when then main thread is the one that initializes Guile. */
  20. #ifdef HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23. #include <pthread.h>
  24. #include <stdlib.h>
  25. #include <libguile.h>
  26. static void *
  27. do_something (void *arg)
  28. {
  29. scm_list_copy (scm_make_list (scm_from_int (1234), SCM_BOOL_T));
  30. scm_gc ();
  31. return NULL;
  32. }
  33. static void *
  34. thread (void *arg)
  35. {
  36. scm_with_guile (do_something, NULL);
  37. return NULL;
  38. }
  39. static void *
  40. inner_main (void *data)
  41. {
  42. int i;
  43. pthread_t thr;
  44. do_something (NULL);
  45. for (i = 0; i < 77; i++)
  46. {
  47. pthread_create (&thr, NULL, thread, NULL);
  48. pthread_join (thr, NULL);
  49. }
  50. return NULL;
  51. }
  52. int
  53. main (int argc, char *argv[])
  54. {
  55. scm_with_guile (inner_main, NULL);
  56. return EXIT_SUCCESS;
  57. }