diff options
-rw-r--r-- | otherlibs/threads/scheduler.c | 19 | ||||
-rw-r--r-- | otherlibs/threads/thread.ml | 4 |
2 files changed, 16 insertions, 7 deletions
diff --git a/otherlibs/threads/scheduler.c b/otherlibs/threads/scheduler.c index efce4af32..ade7df8e6 100644 --- a/otherlibs/threads/scheduler.c +++ b/otherlibs/threads/scheduler.c @@ -157,7 +157,6 @@ static void thread_restore_std_descr(void); value thread_initialize(value unit) /* ML */ { - struct itimerval timer; /* Protect against repeated initialization (PR#1325) */ if (curr_thread != NULL) return Val_unit; /* Create a descriptor for the current thread */ @@ -187,11 +186,6 @@ value thread_initialize(value unit) /* ML */ /* Initialize GC */ prev_scan_roots_hook = scan_roots_hook; scan_roots_hook = thread_scan_roots; - /* Initialize interval timer */ - timer.it_interval.tv_sec = 0; - timer.it_interval.tv_usec = Thread_timeout; - timer.it_value = timer.it_interval; - setitimer(ITIMER_VIRTUAL, &timer, NULL); /* Set standard file descriptors to non-blocking mode */ stdin_initial_status = fcntl(0, F_GETFL); stdout_initial_status = fcntl(1, F_GETFL); @@ -207,6 +201,19 @@ value thread_initialize(value unit) /* ML */ return Val_unit; } +/* Initialize the interval timer used for preemption */ + +value thread_initialize_preemption(value unit) /* ML */ +{ + struct itimerval timer; + + timer.it_interval.tv_sec = 0; + timer.it_interval.tv_usec = Thread_timeout; + timer.it_value = timer.it_interval; + setitimer(ITIMER_VIRTUAL, &timer, NULL); + return Val_unit; +} + /* Create a thread */ value thread_new(value clos) /* ML */ diff --git a/otherlibs/threads/thread.ml b/otherlibs/threads/thread.ml index def5e6230..31fc7f078 100644 --- a/otherlibs/threads/thread.ml +++ b/otherlibs/threads/thread.ml @@ -39,6 +39,7 @@ type resumption_status = must take exactly one argument. *) external thread_initialize : unit -> unit = "thread_initialize" +external thread_initialize_preemption : unit -> unit = "thread_initialize_preemption" external thread_new : (unit -> unit) -> t = "thread_new" external thread_yield : unit -> unit = "thread_yield" external thread_request_reschedule : unit -> unit = "thread_request_reschedule" @@ -135,5 +136,6 @@ let preempt signal = (* Initialization of the scheduler *) let _ = + thread_initialize(); Sys.set_signal Sys.sigvtalrm (Sys.Signal_handle preempt); - thread_initialize() + thread_initialize_preemption() |