short_thread.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include <stdio.h>
  6. #include "nspr.h"
  7. #include "plgetopt.h"
  8. /*
  9. * Create a thread that exits right away; useful for testing race conditions in thread
  10. * creation
  11. */
  12. int _debug_on = 0;
  13. #define DPRINTF(arg) if (_debug_on) printf arg
  14. static void housecleaning(void *cur_time);
  15. int main (int argc, char **argv)
  16. {
  17. static PRIntervalTime thread_start_time;
  18. static PRThread *housekeeping_tid = NULL;
  19. PLOptStatus os;
  20. PLOptState *opt = PL_CreateOptState(argc, argv, "d");
  21. while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  22. {
  23. if (PL_OPT_BAD == os) {
  24. continue;
  25. }
  26. switch (opt->option)
  27. {
  28. case 'd': /* debug mode */
  29. _debug_on = 1;
  30. break;
  31. default:
  32. break;
  33. }
  34. }
  35. PL_DestroyOptState(opt);
  36. if (( housekeeping_tid =
  37. PR_CreateThread (PR_USER_THREAD, housecleaning, (void*)&thread_start_time,
  38. PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0))
  39. == NULL ) {
  40. fprintf(stderr,
  41. "simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
  42. PR_GetError(), PR_GetOSError());
  43. exit( 1 );
  44. }
  45. PR_Cleanup();
  46. return(0);
  47. }
  48. static void
  49. housecleaning (void *cur_time)
  50. {
  51. DPRINTF(("Child Thread exiting\n"));
  52. }