Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: otherlibs/systhreads/st_stubs.c
- ===================================================================
- --- otherlibs/systhreads/st_stubs.c (revision 15967)
- +++ otherlibs/systhreads/st_stubs.c (working copy)
- @@ -95,10 +95,10 @@
- /* The master lock protecting the OCaml runtime system */
- static st_masterlock caml_master_lock;
- -/* Whether the ``tick'' thread is already running */
- +/* Whether the "tick" thread is already running */
- static int caml_tick_thread_running = 0;
- -/* The thread identifier of the ``tick'' thread */
- +/* The thread identifier of the "tick" thread */
- static st_thread_id caml_tick_thread_id;
- /* The key used for storing the thread descriptor in the specific data
- @@ -444,7 +444,12 @@
- CAMLprim value caml_thread_cleanup(value unit) /* ML */
- {
- - if (caml_tick_thread_running) st_thread_kill(caml_tick_thread_id);
- + if (caml_tick_thread_running){
- + caml_tick_thread_stop = 1;
- + st_thread_join(caml_tick_thread_id);
- + caml_tick_thread_stop = 0;
- + caml_tick_thread_running = 0;
- + }
- return Val_unit;
- }
- Index: otherlibs/systhreads/st_win32.h
- ===================================================================
- --- otherlibs/systhreads/st_win32.h (revision 15967)
- +++ otherlibs/systhreads/st_win32.h (working copy)
- @@ -84,11 +84,10 @@
- ExitThread(0);
- }
- -static void st_thread_kill(st_thread_id thr)
- +static void st_thread_join(st_thread_id thr)
- {
- - TRACE1("st_thread_kill", thr);
- - TerminateThread(thr, 0);
- - CloseHandle(thr);
- + TRACE1("st_thread_join", h);
- + WaitForSingleObject(thr, INFINITE);
- }
- /* Scheduling hints */
- @@ -383,18 +382,21 @@
- raise_sys_error(str);
- }
- +/* Variable used to stop the "tick" thread */
- +static volatile int caml_tick_thread_stop = 0;
- +
- /* The tick thread: posts a SIGPREEMPTION signal periodically */
- static DWORD WINAPI caml_thread_tick(void * arg)
- {
- - while(1) {
- + while(! caml_tick_thread_stop) {
- Sleep(Thread_timeout);
- /* The preemption signal should never cause a callback, so don't
- go through caml_handle_signal(), just record signal delivery via
- caml_record_signal(). */
- caml_record_signal(SIGPREEMPTION);
- }
- - return 0; /* prevents compiler warning */
- + return 0;
- }
- /* "At fork" processing -- none under Win32 */
- Index: otherlibs/systhreads/st_posix.h
- ===================================================================
- --- otherlibs/systhreads/st_posix.h (revision 15967)
- +++ otherlibs/systhreads/st_posix.h (working copy)
- @@ -78,14 +78,10 @@
- pthread_exit(NULL);
- }
- -static void st_thread_kill(st_thread_id thr)
- +static void st_thread_join(st_thread_id thr)
- {
- -#if !defined(__ANDROID__)
- - /* pthread_cancel is unsafe, as it does not allow the thread an opportunity
- - to free shared resources such as mutexes. Thus, it is not implemented
- - in Android's libc. */
- - pthread_cancel(thr);
- -#endif
- + pthread_join(thr, NULL);
- + /* best effort: ignore errors */
- }
- /* Scheduling hints */
- @@ -317,6 +313,9 @@
- raise_sys_error(str);
- }
- +/* Variable used to stop the "tick" thread */
- +static volatile int caml_tick_thread_stop = 0;
- +
- /* The tick thread: posts a SIGPREEMPTION signal periodically */
- static void * caml_thread_tick(void * arg)
- @@ -327,11 +326,7 @@
- /* Block all signals so that we don't try to execute an OCaml signal handler*/
- sigfillset(&mask);
- pthread_sigmask(SIG_BLOCK, &mask, NULL);
- -#if !defined(__ANDROID__)
- - /* Allow async cancellation */
- - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
- -#endif
- - while(1) {
- + while(! caml_tick_thread_stop) {
- /* select() seems to be the most efficient way to suspend the
- thread for sub-second intervals */
- timeout.tv_sec = 0;
- @@ -342,7 +337,7 @@
- caml_record_signal(). */
- caml_record_signal(SIGPREEMPTION);
- }
- - return NULL; /* prevents compiler warning */
- + return NULL;
- }
- /* "At fork" processing */
Add Comment
Please, Sign In to add comment