SHARE
TWEET

Untitled

a guest Feb 18th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Index: otherlibs/systhreads/st_stubs.c
  2. ===================================================================
  3. --- otherlibs/systhreads/st_stubs.c (revision 15967)
  4. +++ otherlibs/systhreads/st_stubs.c (working copy)
  5. @@ -95,10 +95,10 @@
  6.  /* The master lock protecting the OCaml runtime system */
  7.  static st_masterlock caml_master_lock;
  8.  
  9. -/* Whether the ``tick'' thread is already running */
  10. +/* Whether the "tick" thread is already running */
  11.  static int caml_tick_thread_running = 0;
  12.  
  13. -/* The thread identifier of the ``tick'' thread */
  14. +/* The thread identifier of the "tick" thread */
  15.  static st_thread_id caml_tick_thread_id;
  16.  
  17.  /* The key used for storing the thread descriptor in the specific data
  18. @@ -444,7 +444,12 @@
  19.  
  20.  CAMLprim value caml_thread_cleanup(value unit)   /* ML */
  21.  {
  22. -  if (caml_tick_thread_running) st_thread_kill(caml_tick_thread_id);
  23. +  if (caml_tick_thread_running){
  24. +    caml_tick_thread_stop = 1;
  25. +    st_thread_join(caml_tick_thread_id);
  26. +    caml_tick_thread_stop = 0;
  27. +    caml_tick_thread_running = 0;
  28. +  }
  29.    return Val_unit;
  30.  }
  31.  
  32. Index: otherlibs/systhreads/st_win32.h
  33. ===================================================================
  34. --- otherlibs/systhreads/st_win32.h (revision 15967)
  35. +++ otherlibs/systhreads/st_win32.h (working copy)
  36. @@ -84,11 +84,10 @@
  37.    ExitThread(0);
  38.  }
  39.  
  40. -static void st_thread_kill(st_thread_id thr)
  41. +static void st_thread_join(st_thread_id thr)
  42.  {
  43. -  TRACE1("st_thread_kill", thr);
  44. -  TerminateThread(thr, 0);
  45. -  CloseHandle(thr);
  46. +  TRACE1("st_thread_join", h);
  47. +  WaitForSingleObject(thr, INFINITE);
  48.  }
  49.  
  50.  /* Scheduling hints */
  51. @@ -383,18 +382,21 @@
  52.    raise_sys_error(str);
  53.  }
  54.  
  55. +/* Variable used to stop the "tick" thread */
  56. +static volatile int caml_tick_thread_stop = 0;
  57. +
  58.  /* The tick thread: posts a SIGPREEMPTION signal periodically */
  59.  
  60.  static DWORD WINAPI caml_thread_tick(void * arg)
  61.  {
  62. -  while(1) {
  63. +  while(! caml_tick_thread_stop) {
  64.      Sleep(Thread_timeout);
  65.      /* The preemption signal should never cause a callback, so don't
  66.       go through caml_handle_signal(), just record signal delivery via
  67.       caml_record_signal(). */
  68.      caml_record_signal(SIGPREEMPTION);
  69.    }
  70. -  return 0;                     /* prevents compiler warning */
  71. +  return 0;
  72.  }
  73.  
  74.  /* "At fork" processing -- none under Win32 */
  75. Index: otherlibs/systhreads/st_posix.h
  76. ===================================================================
  77. --- otherlibs/systhreads/st_posix.h (revision 15967)
  78. +++ otherlibs/systhreads/st_posix.h (working copy)
  79. @@ -78,14 +78,10 @@
  80.    pthread_exit(NULL);
  81.  }
  82.  
  83. -static void st_thread_kill(st_thread_id thr)
  84. +static void st_thread_join(st_thread_id thr)
  85.  {
  86. -#if !defined(__ANDROID__)
  87. -  /* pthread_cancel is unsafe, as it does not allow the thread an opportunity
  88. -     to free shared resources such as mutexes. Thus, it is not implemented
  89. -     in Android's libc. */
  90. -  pthread_cancel(thr);
  91. -#endif
  92. +  pthread_join(thr, NULL);
  93. +  /* best effort: ignore errors */
  94.  }
  95.  
  96.  /* Scheduling hints */
  97. @@ -317,6 +313,9 @@
  98.    raise_sys_error(str);
  99.  }
  100.  
  101. +/* Variable used to stop the "tick" thread */
  102. +static volatile int caml_tick_thread_stop = 0;
  103. +
  104.  /* The tick thread: posts a SIGPREEMPTION signal periodically */
  105.  
  106.  static void * caml_thread_tick(void * arg)
  107. @@ -327,11 +326,7 @@
  108.    /* Block all signals so that we don't try to execute an OCaml signal handler*/
  109.    sigfillset(&mask);
  110.    pthread_sigmask(SIG_BLOCK, &mask, NULL);
  111. -#if !defined(__ANDROID__)
  112. -  /* Allow async cancellation */
  113. -  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  114. -#endif
  115. -  while(1) {
  116. +  while(! caml_tick_thread_stop) {
  117.      /* select() seems to be the most efficient way to suspend the
  118.         thread for sub-second intervals */
  119.      timeout.tv_sec = 0;
  120. @@ -342,7 +337,7 @@
  121.       caml_record_signal(). */
  122.      caml_record_signal(SIGPREEMPTION);
  123.    }
  124. -  return NULL;                  /* prevents compiler warning */
  125. +  return NULL;
  126.  }
  127.  
  128.  /* "At fork" processing */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top