* http://helm.cs.unibo.it/
*)
+(* $Id$ *)
+
let debug = false
-let debug_print s = if debug then prerr_endline s
+let debug_print s = if debug then prerr_endline (Lazy.force s)
class threadSafe =
object (self)
method private doCritical: 'a. 'a lazy_t -> 'a =
fun action ->
- debug_print "<doCritical>";
+ debug_print (lazy "<doCritical>");
(try
Mutex.lock mutex;
let res = Lazy.force action in
Mutex.unlock mutex;
- debug_print "</doCritical>";
+ debug_print (lazy "</doCritical>");
res
with e ->
Mutex.unlock mutex;
method private doReader: 'a. 'a lazy_t -> 'a =
fun action ->
- debug_print "<doReader>";
+ debug_print (lazy "<doReader>");
let cleanup () =
self#decrReadersCount;
self#signalNoReaders
self#incrReadersCount;
let res = (try Lazy.force action with e -> (cleanup (); raise e)) in
cleanup ();
- debug_print "</doReader>";
+ debug_print (lazy "</doReader>");
res
(* TODO may starve!!!! is what we want or not? *)
method private doWriter: 'a. 'a lazy_t -> 'a =
fun action ->
- debug_print "<doWriter>";
+ debug_print (lazy "<doWriter>");
self#doCritical (lazy (
while readersCount > 0 do
Condition.wait noReaders mutex
done;
let res = Lazy.force action in
- debug_print "</doWriter>";
+ debug_print (lazy "</doWriter>");
res
))