hop-2012/util.ml

30 lines
661 B
OCaml
Raw Normal View History

2012-01-08 19:48:07 +00:00
open Sexp
2012-01-08 17:41:04 +00:00
open Printf
let message_not_understood context m =
2012-01-08 19:48:07 +00:00
Log.warn "Message not understood" [Str context; Message.sexp_of_message m]
2012-01-08 17:41:04 +00:00
let create_thread name cleanup main initarg =
let guarded_main initarg =
try
main initarg
with e ->
2012-01-08 19:48:07 +00:00
Log.warn "Thread died with exception" [Str name; Str (Printexc.to_string e)];
2012-01-08 17:41:04 +00:00
(match cleanup with
| Some cleaner -> cleaner ()
| None -> ())
in
Thread.create guarded_main initarg
let with_mutex m f arg =
Mutex.lock m;
try
let result = f arg in
Mutex.unlock m;
result
with e ->
Mutex.unlock m;
raise e
let with_mutex0 m thunk = with_mutex m thunk ()