--- src/event_stubs.c	2007-04-20 14:14:42.000000000 +0300
+++ src2/event_stubs.c	2007-04-20 14:20:20.000000000 +0300
@@ -20,6 +20,7 @@
 #include <caml/memory.h>
 #include <caml/callback.h>
 #include <caml/fail.h>
+#include <caml/signals.h>
 
 #define struct_event_val(v) (*(struct event**) Data_custom_val(v))
 #define Is_some(v) (Is_block(v))
@@ -73,8 +74,11 @@
 static void
 event_cb(int fd, short type, void *arg) 
 {
+  leave_blocking_section();
   callback3(*event_cb_closure, 
 	    Val_long((long) arg), Val_int(fd), Val_int(type));
+  // what happens with exceptions?
+  enter_blocking_section();
 }
 
 static void
@@ -180,8 +184,12 @@
 {
   CAMLparam1(vloop_flag);
 
+  enter_blocking_section();
   if((-1 == event_loop(Int_val(vloop_flag) + 1))) {
+    leave_blocking_section();
     uerror("event_dispatch", vloop_flag);
+  } else {
+    leave_blocking_section();
   }
   
   CAMLreturn(Val_unit);
@@ -193,8 +201,12 @@
 {
   CAMLparam1(unit);
 
+  enter_blocking_section();
   if((-1 == event_dispatch())) {
+    leave_blocking_section();
     uerror("event_dispatch", unit);
+  } else {
+    leave_blocking_section();
   }
 
   CAMLreturn(Val_unit);
