src/Pure/Concurrent/multithreading.ML
changeset 78720 909dc00766a0
parent 78716 97dfba4405e3
child 79601 3430787e0620
equal deleted inserted replaced
78719:89038d9ef77d 78720:909dc00766a0
    65 
    65 
    66 val trace = ref 0;
    66 val trace = ref 0;
    67 
    67 
    68 fun tracing level msg =
    68 fun tracing level msg =
    69   if ! trace < level then ()
    69   if ! trace < level then ()
    70   else Thread_Attributes.uninterruptible (fn _ => fn () =>
    70   else Thread_Attributes.uninterruptible_body (fn _ =>
    71     (TextIO.output (TextIO.stdErr, (">>> " ^ msg () ^ "\n")); TextIO.flushOut TextIO.stdErr)
    71     (TextIO.output (TextIO.stdErr, (">>> " ^ msg () ^ "\n")); TextIO.flushOut TextIO.stdErr)
    72       handle _ (*sic*) => ()) ();
    72       handle _ (*sic*) => ());
    73 
    73 
    74 fun tracing_time detailed time =
    74 fun tracing_time detailed time =
    75   tracing
    75   tracing
    76    (if not detailed then 5
    76    (if not detailed then 5
    77     else if time >= seconds 1.0 then 1
    77     else if time >= seconds 1.0 then 1
    81 
    81 
    82 
    82 
    83 (* synchronized evaluation *)
    83 (* synchronized evaluation *)
    84 
    84 
    85 fun synchronized name lock e =
    85 fun synchronized name lock e =
    86   Exn.release (Thread_Attributes.uninterruptible (fn run => fn () =>
    86   Exn.release (Thread_Attributes.uninterruptible_body (fn run =>
    87     if ! trace > 0 then
    87     if ! trace > 0 then
    88       let
    88       let
    89         val immediate =
    89         val immediate =
    90           if Thread.Mutex.trylock lock then true
    90           if Thread.Mutex.trylock lock then true
    91           else
    91           else
   103     else
   103     else
   104       let
   104       let
   105         val _ = Thread.Mutex.lock lock;
   105         val _ = Thread.Mutex.lock lock;
   106         val result = Exn.capture0 (run e) ();
   106         val result = Exn.capture0 (run e) ();
   107         val _ = Thread.Mutex.unlock lock;
   107         val _ = Thread.Mutex.unlock lock;
   108       in result end) ());
   108       in result end));
   109 
   109 
   110 end;
   110 end;